Story: Zoggโs Supplies Are Confusing!
Zogg has learned to store supplies in a list. But now, thereโs a new problemโฆ
โWait! How do I know how many Oxygen Tanks I have? My list just has names!โ
โZogg, use a dictionary!โ the spaceshipโs AI suggests.
โA dictionary? Like a book?โ
Not quite, Zogg! In Python, a dictionary helps us store pairs of informationโlike what we have and how many!
Step 1: Creating a Dictionary
A dictionary uses {}
curly brackets and stores key-value pairs:
supplies = {
"Oxygen Tanks": 3,
"Food Packs": 10,
"Fuel Cells": 5,
"Space Suits": 2
}
print(supplies)
Keys = Names of supplies
Values = How many we have
Now, Zogg knows both what he has and how much!
Step 2: Accessing Dictionary Values
Zogg wants to check how many Fuel Cells he has. Instead of searching a list, he can look it up instantly!
print(supplies["Fuel Cells"]) # Output: 5
Dictionaries let us quickly find what we need!
Step 3: Updating Values in a Dictionary
Zogg just used one Oxygen Tank. Letโs update the count!
supplies["Oxygen Tanks"] -= 1 # Uses 1 Oxygen Tank
print(supplies)
Dictionaries let us modify values easily!
Step 4: Adding & Removing Items
Zogg found a Repair Kit. Letโs add it to the dictionary!
supplies["Repair Kit"] = 1
print(supplies)
Now, Repair Kit is part of the inventory!
But waitโone Space Suit is torn! Letโs remove it:
del supplies["Space Suits"]
print(supplies)
Now the Space Suits are gone!
Step 5: Looping Through a Dictionary
Zogg wants a full report of his supplies! Letโs loop through the dictionary:
for item, count in supplies.items():
print(item + ": " + str(count))
Now, Python lists all supplies and their amounts!
Challenge: Track Space Mission Supplies!
Zoggโs spaceship just restocked with: 7 Water Bottles
3 Energy Bars
Mission: Add them to the dictionary and print the full list!
supplies = {
"Oxygen Tanks": 3,
"Food Packs": 10,
"Fuel Cells": 5
}
# Step 1: Add Water Bottles & Energy Bars
___
___
# Step 2: Print the updated inventory
print(___)
Can you complete the mission? Post your answer in the comments!
Common Mistakes & Fixes!
Forgetting to use quotes for dictionary keys
supplies = {Oxygen Tanks: 3} #
ERROR!
Fix:
supplies = {"Oxygen Tanks": 3} #
Works!
Using
=
instead of :
in dictionaries
supplies = {"Oxygen Tanks" = 3} #
ERROR!
Fix:
supplies = {"Oxygen Tanks": 3} #
Works!
Fun Fact: Dictionaries Are Super Fast!
Looking up values in a dictionary is much faster than searching a list, especially when dealing with huge amounts of data! Thatโs why Python uses them in AI, games, and databases.
Next Mission: โFunctions โ Giving Python Superpowers!โ 

Now that Zogg has organized his supplies, he wants to make his spaceship more efficient. But typing the same code over and over is getting frustrating!
โIsnโt there a way to make Python do tasks for me?โ Zogg wonders.
Yes! In the next mission, weโll learn about functionsโspecial mini-programs inside Python that can save time, reduce errors, and make your code super powerful!
Get ready to write your own functions and make Python work for you!
See you in the next adventure, Junior Python Coder!