Answer: Python Puzzler #46

The answer is D. The program prints:

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

Why?

len counts every character, including spaces and punctuation. ‘robot’ has 5.

Trace table

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

countcharacter
1r
2o
3b
4o
5t

The code again

word = "robot"
print(len(word))

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