The supply closet at Mission Control is a mystery. Nobody knows how many flashlights are left, and the clipboard list on the door is covered in crossed-out numbers.
"A dictionary," Rocket says right away. "Item names as keys, amounts as values. We update it as things come and go."
Raven opens the closet and starts counting. "What do you notice?" she asks. "Some items come in, some go out. The program needs to add and take away."
Nova scans the shelves with a soft beam. "Interesting," she says. "If someone takes an item that is not on the list, what should happen? Decide before you code."
Rocket writes the question in his notebook and circles it.
# inventory.py
stock = {"flashlight": 4, "rope": 2, "tape": 6}
stock["rope"] = stock["rope"] - 1
stock["batteries"] = stock.get("batteries", 0) + 8
for item, amount in stock.items():
print(f"{item}: {amount}") flashlight: 4 rope: 1 tape: 6 batteries: 8
Excellent work. Next week you will package your code into functions and modules.