Grade 7 Computer Science — Variables in a program
Follow what a named value holds as a program changes it line by line, and say what it holds at the end.
Name: ________________________
1.A program has set score to 6. Match each line that runs next to what score holds afterwards.
- add 4 to score
- take 4 away from score
- set score to 4
- set score to score times 4
- add score to score
- 2
- 24
- 12
- 10
- 4
2.A program says: set m to 9; set m to m plus m. What does m hold now?
- a) 0
- b) 9
- c) 81
- d) 18
3.A program says: set total to 4; set total to 7; print total. What appears on the screen?
- a) 4
- b) 11
- c) First 4 and then 7
- d) 7
4.A program says: set x to 3; set y to x; set x to 8. What does y hold now?
5.Sort each line by whether it changes what total holds.
Groups: Changes it · Leaves it as it was
- compare total with 10
- set total to 0
- take 2 away from total
- print total
- add 5 to total
- show total on the screen
6.A program says: set a to 6; set b to 4; set a to a plus b. What does a hold now?
7.A program says: set price to 20; set price to price times 2. What does price hold now?
- a) 2
- b) 20
- c) 22
- d) 40
8.A program says: set score to 5; add 3 to score. What does score hold now?
Answer key — Grade 7 Computer Science — Variables in a program
- 1. add 4 to score → 10; take 4 away from score → 2; set score to 4 → 4; set score to score times 4 → 24; add score to score → 12
- 2. d) 18
- 3. d) 7
- 4. 3
- 5. add 5 to total → Changes it; print total → Leaves it as it was; set total to 0 → Changes it; show total on the screen → Leaves it as it was; take 2 away from total → Changes it; compare total with 10 → Leaves it as it was
- 6. 10
- 7. d) 40
- 8. 8