Answer: Python Puzzler #2499

The answer is B. The program prints:

49

This answer was checked by running the program for real.

Why?

range(1, 14, 2) starts at 1, goes up in steps of 2, and stops before 14. So the loop adds 1 + 3 + 5 + 7 + 9 + 11 + 13. The total is 49.

Trace table

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

numbertotal after the loop body
11
34
59
716
925
1136
1349

The code again

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

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