──────────────────────────────────────

2. Broadcast from Base Camp · Give a Robot a Profile

Store text, a whole number and a yes-or-no value, then change a stored value.

Lesson files · lessons/first-programs/variables-and-types

Before you start
- Show a message with print().

By the end
- Use variables to store text, a whole number and True or False.
- Trace what print() shows before and after a variable is reassigned.

Where you can use it
Keep a player’s name, score and ready status in variables. Update the score when the player earns a point.

An assignment uses = to store a value under a name. The robot variable holds a string, which is Python's name for text. The battery variable holds an integer, or whole number. The online variable holds a Boolean, which is either True or False.

When you write print(battery), Python looks up the value that battery holds at that moment. In the example that value is 80 on the first call and 65 after the next assignment.

Predict
Which value is printed after battery = 65?
- 80
- 65

Worked example (example.py)

robot = "Pip"
battery = 80
online = True
print(robot)
print(battery)
battery = 65
print(battery)
print(online)


Example result
Pip
80
65
True

Set robot to Nova, battery to 90 and online to False. Print the name, battery and online state in that order.

Starter program (starter.py)

robot = "Pip"
battery = 80
online = True
print(robot)
print(battery)
battery = 65
print(battery)
print(online)


Hint
Use quotes for Nova. Write 90 and False without quotes so the values keep their Python types.

Case 1. Try the sample
Input
(No input.)
Expected output
Nova
90
False

Stretch
Print the battery, use battery = battery - 15 to save the new level, then print it again.

Reflect
What would change if you wrote print("robot")?

Check your prediction
65 The second assignment changes what battery refers to. It leaves the earlier output alone.
