Answer: Python Puzzler #745

The answer is A. The program prints:

30
What the program prints
Checked by running the program for real.

Why?

range(0, 13, 3) starts at 0, goes up in steps of 3, and stops before 13. So the loop adds 0 + 3 + 6 + 9 + 12. The total is 30.

Trace table

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

numbertotal after the loop body
00
33
69
918
1230

The code again

total = 0
for number in range(0, 13, 3):
    total = total + number
print(total)

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