Chapter 3 · Quest 2 of 5 · 10 XP
Weather Window
🌦️ Tools often look things up. A dictionary stores pairs: a key and its value. You read a value with square brackets, and in tells you if a key is there.
ages = {"Sam": 12, "Ada": 14}
print(ages["Ada"])
print("Bo" in ages)14 False
Your bot can't see outside, so give it a weather tool. Asking for a key that isn't there crashes, so check with in first.
Instructions
- Make a function
weather(city). - If
cityis inWEATHER, return it likeParis: rainy. - Otherwise return
I don't know Atlantis.(with the city's name). - Print
weather("Tokyo").
💡 Hint
if city in WEATHER: return city + ": " + WEATHER[city]. Then else: return "I don't know " + city + "."
bot.py
Terminal