Answer: Python Puzzler #397

The answer is D. The program prints:

CCC
OOO
DDD
EEE
What the program prints
Checked by running the program for real.

Why?

A for loop can go through a string one letter at a time. Each letter is printed 3 times in a row.

Trace table

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

letterprinted
CCCC
OOOO
DDDD
EEEE

The code again

for letter in "CODE":
    print(letter * 3)

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