Answer: Python Puzzler #1834

The answer is A. The program prints:

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

Why?

word[1:5] is a slice: it starts at position 1 and stops before position 5. Positions count from 0.

Trace table

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

positionletter
0K
1E
2Y
3B
4O
5A
6R
7D

The code again

word = "KEYBOARD"
print(word[1:5])

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