Prev
Variables & Storing Information
Challenge In Progress
0
20
5
P

Creating Helpful Names for Your Data & Updating Values

In programming, you frequently need to remember information so you can use it later. For example, if you are making a video game, you need to remember the player's name, their score, and how many levels they have completed. In Python, we do this using a variable. A variable is simply a friendly name that you attach to a piece of data so you can refer to it whenever you need it.
To create a variable, you write the name you want to use, followed by an equals sign (=), followed by the value you want to store. For example, writing score = 100 tells Python: "Create the number 100, and attach the label 'score' to it." In Python, the = sign does not mean "these two sides are equal" like in math class. Instead, it is called the assignment operator. You can think of it as an arrow pointing to the left: "take the value on the right, and store it under the name on the left."
Variables can hold all kinds of information, including whole numbers (like 100), decimal numbers (like 99.5), and text wrapped in quotes (like "Alex"). You do not have to announce in advance what kind of information a variable will hold. Python inspects the value you provide and automatically figures out its type. This helpful behavior is called dynamic typing. You can inspect what kind of data a variable holds at any time using Python's built-in type() tool.
Because variables are names pointing to values rather than permanently locked boxes, you can reassign them whenever your program needs an update. If a player scores 50 points, you can write score = score + 50. Python calculates 100 + 50 to get 150, and then moves the name score to point at the new total. To keep your code clean, readable, and professional, always write variable names using lowercase words separated by underscores, such as player_score or user_email. This standard style is known as snake_case.
Real-World Analogy
Think of a variable as a sticky luggage tag at an airport, and the value as the suitcase. When you write score = 100, you stick a tag named "score" onto a suitcase containing 100. If you later write score = 150, you aren't repainting the suitcase—you are simply moving the sticky tag to a new suitcase containing 150!
Code ExamplePython 3
# Step 1: Attach the name 'player_score' to the number 100
player_score = 100
print("Current score:", player_score)
print("Type of score:", type(player_score))

# Step 2: Add 50 points and update the variable
player_score = player_score + 50
print("Updated score:", player_score)

# Step 3: Variables can also hold text
player_name = "Alex"
print("Player name:", player_name)
print("Type of name:", type(player_name))
Key Rules & Concepts
  • A variable is a descriptive name attached to a value so you can reuse and update it.
  • The = symbol is the assignment operator: it stores the value on the right under the name on the left.
  • Python uses dynamic typing: it automatically detects the type of value without needing manual declarations.
  • Reassigning a variable moves the name tag to a new value rather than modifying the original value.
  • Follow Python style conventions: write variable names in lowercase with underscores (snake_case).

Challenge

Beginner

Manage game score points by tracking initial base points, calculating total points with a bonus, and verifying value updates.

What to do:

  1. Create a variable base_points with value 100
  2. Create bonus_points with value 50
  3. Calculate total_points = base_points + bonus_points
  4. Create a boolean variable is_updated = True
  5. Print "Base points: ", base_points
  6. Print "Total points: ", total_points
  7. Print "Updated: ", is_updated
Reference Solution Locked
0 Attempts

Solve the challenge above and run your code to verify it. If you are stuck, you can unlock the reference solution after running your code at least once.

Previous Lesson
Python
Write Code
1
2
3
4
5
6
7
8
9
10
# Game score tracking
# TODO: Define base_points = 100
# TODO: Define bonus_points = 50
# TODO: Calculate total_points = base_points + bonus_points
# TODO: Define is_updated = True

# TODO: Print "Base points:", base_points
# TODO: Print "Total points:", total_points
# TODO: Print "Updated:", is_updated

TEST CASESCONSOLE
Output
// Press "Run Code" to execute
Expected Output
Base points: 100 Total points: 150 Updated: True