Answer: Python Puzzler #903

The answer is D. The program prints:

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

Why?

The outer loop runs 4 times (one per row). Inside it, the inner loop adds 2 symbols to line. So you get 4 rows of 2.

Trace table

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

rowline printed
0oo
1oo
2oo
3oo

The code again

for row in range(4):
    line = ""
    for col in range(2):
        line = line + "o"
    print(line)

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