Answer: Python Puzzler #508

The answer is B. The program prints:

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

Why?

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

Trace table

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

lettermatches?
r
oyes
b
oyes
t
(space)
r
oyes
b
oyes
t

The code again

word = "robot robot"
print(word.count("o"))

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