Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Variables and Operations | Section 1
Python - Sport
course content

Course Content

Python - Sport

Python - Sport

1. Section 1
2. Section 2

book
Variables and Operations

Welcome to your first adventure in Python programming! Imagine stepping onto a sports field, ready to learn the basics. Today, we'll explore variables, naming rules, print statements, and math operations in Python.

Think of variables as lockers where you store your gear. In Python, variables hold data values. For example, if you're tracking a basketball player's performance, you might create a variable called player_score to store the number of points they score in a game:

python

Naming variables is like choosing a nickname that reflects your role on the team. Start with a letter or an underscore, and remember that Python is case-sensitive, so score and Score are different. Choose descriptive names like total_distance for clarity. Avoid using reserved words like print or if.

Once you've got your variables, it's time to communicate with your audience. The print() function in Python is your microphone, allowing you to display information. For example:

12345
player_name = "John" player_score = 10 print("Player:", player_name) print("Score:", player_score)
copy

In Python, variable names must adhere to specific rules to be valid. Below is a code example that illustrates some common mistakes when naming variables

python

Python is great at handling math operations, similar to calculating a player's average speed. You can add, subtract, multiply, and divide numbers:

python
Task

Swipe to start coding

Your goal is to complete calculate_game_excitement_index function that calculates the Game Excitement Index for an NFL game. This index quantifies the excitement level based on total points scored and how close the game was.

✨ Bonus: See Your Results Visualized! ✨

By finishing the task using the specified steps, you'll unlock a chart that visualizes your results. This chart will provide a clear and engaging representation of the excitement index you've calculated.

Code Instructions:

  • Inputs:

    1. team1_score: The score of the first team.
    2. team2_score: The score of the second team.
  • Steps:

  1. Declare a variable total_points and assign it the sum of team1_score and team2_score
  2. Declare a variable point_difference and assign it the absolute difference between team1_score and team2_score. Use the abs() function to ensure the result is non-negative.
  3. Create a variable excitement_index and calculate it by dividing total_points by (point_difference + 1).
  4. Ensure your function returns the excitement_index.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 1
toggle bottom row

book
Variables and Operations

Welcome to your first adventure in Python programming! Imagine stepping onto a sports field, ready to learn the basics. Today, we'll explore variables, naming rules, print statements, and math operations in Python.

Think of variables as lockers where you store your gear. In Python, variables hold data values. For example, if you're tracking a basketball player's performance, you might create a variable called player_score to store the number of points they score in a game:

python

Naming variables is like choosing a nickname that reflects your role on the team. Start with a letter or an underscore, and remember that Python is case-sensitive, so score and Score are different. Choose descriptive names like total_distance for clarity. Avoid using reserved words like print or if.

Once you've got your variables, it's time to communicate with your audience. The print() function in Python is your microphone, allowing you to display information. For example:

12345
player_name = "John" player_score = 10 print("Player:", player_name) print("Score:", player_score)
copy

In Python, variable names must adhere to specific rules to be valid. Below is a code example that illustrates some common mistakes when naming variables

python

Python is great at handling math operations, similar to calculating a player's average speed. You can add, subtract, multiply, and divide numbers:

python
Task

Swipe to start coding

Your goal is to complete calculate_game_excitement_index function that calculates the Game Excitement Index for an NFL game. This index quantifies the excitement level based on total points scored and how close the game was.

✨ Bonus: See Your Results Visualized! ✨

By finishing the task using the specified steps, you'll unlock a chart that visualizes your results. This chart will provide a clear and engaging representation of the excitement index you've calculated.

Code Instructions:

  • Inputs:

    1. team1_score: The score of the first team.
    2. team2_score: The score of the second team.
  • Steps:

  1. Declare a variable total_points and assign it the sum of team1_score and team2_score
  2. Declare a variable point_difference and assign it the absolute difference between team1_score and team2_score. Use the abs() function to ensure the result is non-negative.
  3. Create a variable excitement_index and calculate it by dividing total_points by (point_difference + 1).
  4. Ensure your function returns the excitement_index.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 1
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt