Answer: Python Puzzler #3639

The answer is D. The program prints:

quack

This answer was checked by running the program for real.

Why?

A dictionary stores pairs: a key and its value. sounds["duck"] looks up the key ‘duck’ and gives back its value.

Trace table

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

keyvalue
catmeow
beebuzz
sheepbaa
duckquack

The code again

sounds = {
    "cat": "meow",
    "bee": "buzz",
    "sheep": "baa",
    "duck": "quack",
}
print(sounds["duck"])

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