What does the program print? (Python) – practice for Years 7–9
Sample questions on What does the program print? (Python) with the right answer and a worked solution, from easy to hard. In the Pickles Academy app a child gets new questions of the same kind every time, so they can't just learn the answers by heart.
- Subject
- Computing
- Year
- Years 7–9
- Curriculum area
- Algorithms and programming
Question types: What does it print?
Rule: What does the program print? (Python)
Run the program line by line and write down the variables. x = x + 3 means: add 3 to x.
range(1, 5) gives 1, 2, 3, 4 but not 5. // is whole-number division, % the remainder.
Example: s = 0, then for i in range(1, 4): s = s + i → 1 + 2 + 3, it prints 6
Watch out: range(1, 5) never reaches 5: the loop runs 4 times, not 5.
Sample questions
-
Question 1 Easy
What does this program print?
a = 8 b = 8 c = a + b * 2 b = (a + b) * 2 print(b)
Show the solution
Answer: 32How it works: Values of b: 8 → 32. The program prints 32.
-
Question 2 Normal
What does this program print?
p = 1 for i in range(3): p = p * 3 print(p)
Show the solution
Answer: 27How it works: Values of p: 1 → 3 → 9 → 27. The program prints 27.
-
Question 3 Hard
What does this program print?
s = 0 for i in range(1, 9): if i % 2 == 0: s = s + i else: s = s - 1 print(s)
Show the solution
Answer: 16How it works: Values of s: 0 → −1 → 1 → 0 → 4 → 3 → 9 → 8 → 16. The program prints 16.
Keep practising in the app
In a minute, your child has their own avatar and a first task. Free, no ads, data in the EU.
Start for free