Computing · Year 4
Bell.Study
Variables in programs
Using variables to store values like score and lives. Variables can change as the program runs
- 1
What is a variable in a program? A) A named place that stores a value B) A type of computer C) A button on the keyboard D) A part of the screen
Answer: - 2
True or false? A variable can change its value while the program is running. A) True B) False
Answer: - 3
Which of these would be a good name for a variable in a game? A) score B) blue C) fast D) sometimes
Answer: - 4
Complete the line of code. At the start of a new game, score = ___.
Answer: - 5
score = 5. The code says: score = score + 1. What is the new value of score? A) 6 B) 5 C) 1 D) 0
Answer: - 6
Match each variable to what it might store in a game. Match each item on the left to one on the right. Left: score, lives, name, level Right: Number of points, How many tries left, Player's name, Which stage of the game
Answer: - 7
True or false? A variable can only hold numbers. A) True B) False
Answer: - 8
Complete the sentence about variables. Variables have a ___ and a value. The name labels the variable.
Answer: - 9
score = 10, then: score = score + 5, then: score = score - 3. What is the final score? A) 12 B) 10 C) 15 D) 8
Answer: - 10
Why use a variable instead of typing the number again and again? A) You can change the value in one place and it updates everywhere B) It uses more memory C) It looks cooler D) It is slower
Answer:
Answer key
Variables in programs · for parents and teachers
- 1
A named place that stores a value
A variable is a named place in memory that stores a value, such as a number or some text.
- 2
True
True. A variable can change (vary). For example, a score can go up or down during a game.
- 3
score
'score' is a good name because it clearly says what the variable holds.
- 4
0
Most games start with the score set to 0. We set the variable like this: score = 0.
- 5
6
'score = score + 1' adds 1 to the score. 5 + 1 = 6, so score is now 6.
- 6
score → Number of points; lives → How many tries left; name → Player's name; level → Which stage of the game
Variables hold useful information in a game, such as score, lives, name and level.
- 7
False
False. Variables can hold numbers, text (like a name), and other types of data too.
- 8
name
Every variable has a name (a label) and a value (what is stored).
- 9
12
Step by step: 10 + 5 = 15, then 15 - 3 = 12. The final score is 12.
- 10
You can change the value in one place and it updates everywhere
Variables let you change a value in one place. All other uses update automatically.