Chapter 4 · Quest 1 of 5 · 10 XP
Sticky Note
🗒️ Your bot forgets everything the moment a program ends. Memory starts small: a dictionary of sticky notes. You can add a new key at any time, or write over one:
notes = {}
notes["snack"] = "popcorn"
notes["snack"] = "nachos"
print(notes){'snack': 'nachos'}.get(key, backup) reads a note, or gives back the backup if the key isn't there, instead of crashing.
Instructions
- Make an empty dict called
notes. - Make
remember(key, value)that stores the value innotes. - Make
recall(key)that returns the note, orI don't remember that. - Remember that
"color"is"teal", then printrecall("color").
💡 Hint
remember does notes[key] = value. recall does return notes.get(key, "I don't remember that.").
bot.py
Terminal