Year 8 Computing — 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.Put these four lines in an order that leaves total holding 14 and then shows it.
- add 8 to total
- set total to 0
- add 6 to total
- print total
2.Sort each line by whether it changes what total holds.
Groups: Changes it · Leaves it as it was
- take 2 away from total
- show total on the screen
- print total
- add 5 to total
- set total to 0
- compare total with 10
3.A program says: set a to 6; set b to 4; set a to a plus b. What does a hold now?
4.A program says: set a to 2; set b to 5; set c to a plus b; set a to 10. What does c hold now?
5.A program says: set n to 12; take 4 away from n; take 3 away from n. What does n hold now?
6.A program says: set a to 6; set b to 4; set a to a plus b. What does b hold now?
7.A program says: set score to 5; add 3 to score. What does score hold now?
8.A program says: set price to 20; set price to price times 2. What does price hold now?
- a) 20
- b) 40
- c) 22
- d) 2
Answer key — Year 8 Computing — Variables in a program
- 1. 1. set total to 0 2. add 6 to total 3. add 8 to total 4. print totalAlso accepted, in full:
- 1. set total to 0 2. add 8 to total 3. add 6 to total 4. print total
- 2. 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
- 3. 10
- 4. 7
- 5. 5
- 6. 4
- 7. 8
- 8. b) 40