Variables: Boxes That Remember
How does a game remember your score?
Real Python code
This is the code from the video. Read it out loud like a recipe, one line at a time!
score = 0
score = score + 10
score = score + 10
print(score)
print("score")
Quiz time!
What will this print?
lives = 3
lives = lives - 1
print(lives)
A box with a label
The box
A little spot in the computer's memory
The label
The box's name, like score
What's inside
One thing, like the number 0
What we learned
No variables
- The game forgets your score
- Nothing to count with
- Can't change as you play
With variables
- A box with a name
- Set it, change it, show it
- One value at a time
Variables are boxes that remember!
Try it yourself!
In Scratch, make a score variable and add one each time you click the sprite.
Bit is working on the next one: If / Else: pick a path