Answer: Python Puzzler #3995

The answer is D. The program prints:

1
2
3
4
Zap
6
7
8
9
Zap

This answer was checked by running the program for real.

Why?

Every number that divides exactly by 5 (remainder 0) is replaced by ‘Zap’. All the others are printed as they are.

Trace table

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

numbernumber % 5printed
111
222
333
444
50Zap
616
727
838
949
100Zap

The code again

for number in range(1, 11):
    if number % 5 == 0:
        print("Zap")
    else:
        print(number)

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