Answer: Python Puzzler #737

The answer is D. The program prints:

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

Why?

range(2, 15, 2) starts at 2, goes up in steps of 2, and stops before 15. So the loop adds 2 + 4 + 6 + 8 + 10 + 12 + 14. The total is 56.

Trace table

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

numbertotal after the loop body
22
46
612
820
1030
1242
1456

The code again

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

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