lives = 3; lives = lives + 2. What does lives hold now?
COMPUTING AND DIGITAL LITERACY
This document was made by AI and there may be mistakes. If a question or answer looks wrong, use the Flag a mistake button to let Brett know so he can fix it.
This is how a program remembers a value and uses it later, like your score in a game or the total in a shopping cart, so it does not have to ask you for it every time. A variable is a named box where the program stores a value, and it can read that value back whenever it needs it. When the value changes, the program updates the box, and every later use sees the new value. That is how a game keeps your score, a cart keeps your total, and any program remembers what has happened so far.
How do you create a variable called score starting at 0, then add 10 to it?
Solution
score = 0
score = score + 10
Now score holds 10.
Create the variable with a name and a starting value: score = 0
Add 10 by writing score = score + 10, which reads the old value, adds 10, and stores the result.
Read score again and it now holds 10, not 0.
How do you store the name Sam in a variable and print it?
Solution
name = "Sam"
print(name)
Output: Sam
Store the text in a variable: name = "Sam". The quotes mark it as text.
Ask the program to print the variable, not the word name: print(name).
The output shows Sam, the value stored inside name.
lives = 3; lives = lives + 2. What does lives hold now?
What does 'score = score + 10' do if score holds 5?
points = 20; points = points + 5. What does points hold now?
coins = 3; coins = coins + 2; coins = coins + 4. What does coins hold now?
name = 'Maya'; print(name). What prints?
name = 'Maya'; name = 'Lee'; print(name). What prints?
score = 10; bonus = score; What does bonus hold?
What does print(score) show?
What is a variable?
Why give a variable a clear name?
Your score: 0 / 10
1. 5
2. It makes score hold 15
3. 25
4. 9
5. Maya
6. Lee
7. 10
8. The value stored in score
9. A named place that stores a value a program can read and change
10. So anyone reading the code knows what it holds