Answer: Python Puzzler #2841

The answer is A. The program prints:

plum

This answer was checked by running the program for real.

Why?

Python counts list positions from 0, so position 5 is the sixth item.

Trace table

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

positionnegative positionitem
0-6carrot
1-5mango
2-4grape
3-3pear
4-2melon
5-1plum

The code again

basket = ["carrot", "mango", "grape", "pear", "melon", "plum"]
print(basket[5])

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