Class 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 says: set a to 6; set b to 4; set a to a plus b. What does b hold now?
2.A program says: set a to 6; set b to 4; set a to a plus b. What does a hold now?
3.A program says: set total to 4; set total to 7; print total. What appears on the screen?
- a) First 4 and then 7
- b) 7
- c) 4
- d) 11
4.Put these four lines in an order that leaves total holding 14 and then shows it.
- print total
- set total to 0
- add 8 to total
- add 6 to total
5.Sort each line by whether it changes what total holds.
Groups: Changes it · Leaves it as it was
- show total on the screen
- print total
- add 5 to total
- take 2 away from total
- set total to 0
- compare total with 10
6.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?
7.A program says: set x to 3; set y to x; set x to 8. What does y hold now?
8.A program says: set score to 5; add 3 to score. What does score hold now?
Answer key — Class 7 Computer Science — Variables in a program
- 1. 4
- 2. 10
- 3. b) 7
- 4. 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
- 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. 7
- 7. 3
- 8. 8