Answer: Python Puzzler #413

The answer is C. The program prints:

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

Why?

count goes through the string and counts how many times ‘p’ appears.

Trace table

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

lettermatches?
pyes
r
o
g
r
a
m
m
i
n
g

The code again

word = "programming"
print(word.count("p"))

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