Answer: Python Puzzler #1697

The answer is B. The program prints:

True
What the program prints
Checked by running the program for real.

Why?

First Python works out each side: 5 > 1 is True and 1 < 7 is True. and is True only if both sides are True.

Trace table

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

partvalue
5 > 1True
1 < 7True

The code again

print(5 > 1 and 1 < 7)

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