🐸

The Codex

Python Basicspython-basics-29-the-codex
Reward: 140 XP
|

The Codex

Hoppy found an ancient spellbook (The Codex). It doesn't just store items; it connects names to meanings.

In Python, this is called a Dictionary. It stores data in key: value pairs.

Creating a Dictionary

# A dictionary of spells
spells = {
  "fire": "Burn!",
  "ice": "Freeze!",
  "heal": "Restore!"
}

# A dictionary of character stats
hoppy = {
  "name": "Hoppy",
  "level": 5,
  "is_hero": True
}

Your Mission

1
The Book

Create a dictionary named spellbook.

2
Entries

Add two entries:

  • Key "light" with value "Lumos"
  • Key "open" with value "Alohomora"
3
Show

Print the spellbook.

Suggested Solution
Click to expand

Use curly braces {} and colons :.

spellbook = {
  "light": "Lumos",
  "open": "Alohomora"
}
print(spellbook)
Advanced Tips
Want more? Click to expand

Keys must be unique! If you use the same key twice, the second one overwrites the first.

data = {"a": 1, "a": 2}
print(data) # Output: {'a': 2}
pymain.py
Loading...
Terminal
Terminal
Ready to run...