Answer: Python Puzzler #2353

The answer is C. The program prints:

Slow and steady.

This answer was checked by running the program for real.

Why?

Python checks the conditions from the top and runs the first one that is true. Is 9 > 13? No. Is 9 > 7? Yes.

Trace table

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

questionanswer
battery > 13False
battery > 7True

The code again

battery = 9
if battery > 13:
    print("Full speed ahead!")
elif battery > 7:
    print("Slow and steady.")
else:
    print("Time to recharge!")

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