Answer: Python Puzzler #942

The answer is C. The program prints:

9
7
5
3
1
Lift off!
What the program prints
Checked by running the program for real.

Why?

The loop keeps going while count > 0. Each time round it prints count, then takes away 2. When count reaches -1, the condition is false, the loop stops, and the last line prints.

Trace table

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

countcount > 0?new count
9yes7
7yes5
5yes3
3yes1
1yes-1
-1no (stop)

The code again

count = 9
while count > 0:
    print(count)
    count = count - 2
print("Lift off!")

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