Answer: Python Puzzler #1917

The answer is C. The program prints:

1
Boop
3
Boop
5
Boop
7
Boop
9
What the program prints
Checked by running the program for real.

Why?

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

Trace table

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

numbernumber % 2printed
111
20Boop
313
40Boop
515
60Boop
717
80Boop
919

The code again

for number in range(1, 10):
    if number % 2 == 0:
        print("Boop")
    else:
        print(number)

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