Answer: Python Puzzler #1385

The answer is C. The program prints:

5
10
15
20
What the program prints
Checked by running the program for real.

Why?

% gives the remainder after dividing. A remainder of 0 means the number divides exactly by 5, so the program prints the multiples of 5 up to 20.

Trace table

A trace table follows the program step by step. Here’s this one:

numbernumber % 5printed?
11
22
33
44
50yes
61
72
83
94
100yes
111
122
133
144
150yes
161
172
183
194
200yes

The code again

for number in range(1, 21):
    if number % 5 == 0:
        print(number)

Try it: change one number in the program and predict the new output before you run it.