Conteúdo do Curso
Python - Sport
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:
player_name = "John" player_score = 10 print("Player:", player_name) print("Score:", player_score)
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
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:
team1_score
: The score of the first team.team2_score
: The score of the second team.
-
Steps:
- Declare a variable
total_points
and assign it the sum ofteam1_score
andteam2_score
- Declare a variable
point_difference
and assign it the absolute difference betweenteam1_score
andteam2_score
. Use theabs()
function to ensure the result is non-negative. - Create a variable
excitement_index
and calculate it by dividingtotal_points
by (point_difference
+ 1). - Ensure your function returns the
excitement_index
.
Solução
Obrigado pelo seu feedback!
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:
player_name = "John" player_score = 10 print("Player:", player_name) print("Score:", player_score)
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
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:
team1_score
: The score of the first team.team2_score
: The score of the second team.
-
Steps:
- Declare a variable
total_points
and assign it the sum ofteam1_score
andteam2_score
- Declare a variable
point_difference
and assign it the absolute difference betweenteam1_score
andteam2_score
. Use theabs()
function to ensure the result is non-negative. - Create a variable
excitement_index
and calculate it by dividingtotal_points
by (point_difference
+ 1). - Ensure your function returns the
excitement_index
.
Solução
Obrigado pelo seu feedback!