Answer: Python Puzzler #1436

The answer is B. The program prints:

2
4
6
8
10
12
14
16
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 2, so the program prints the multiples of 2 up to 16.

Trace table

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

numbernumber % 2printed?
11
20yes
31
40yes
51
60yes
71
80yes
91
100yes
111
120yes
131
140yes
151
160yes

The code again

for number in range(1, 17):
    if number % 2 == 0:
        print(number)

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