Answer: Python Puzzler #452

The answer is A. The program prints:

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

Why?

range(3, 6, 2) starts at 3, goes up in steps of 2, and stops before 6. So the loop adds 3 + 5. The total is 8.

Trace table

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

numbertotal after the loop body
33
58

The code again

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

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