0%
⭐ 0 XPMap
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

  1. Make a function weather(city).
  2. If city is in WEATHER, return it like Paris: rainy.
  3. Otherwise return I don't know Atlantis. (with the city's name).
  4. Print weather("Tokyo").
💡 Hint

if city in WEATHER: return city + ": " + WEATHER[city]. Then else: return "I don't know " + city + "."

Ask the community

bot.py
Terminal
← BackNext →

Chapter 3: Tools

The full quest map

Talk it out

  1. Read the instruction with the ✗ out loud.
  2. Say what your code does, line by line, as if to a friend.
  3. Find the line where what it does and what you want split apart.
  4. Press Run and read the terminal. Is that what you expected?
  5. Still stuck? Press Ask Pip why, or peek at the solution.
  6. Or ask on the community help board: say which quest, and paste your code.
New badge!

Your bot just got a new part. See it on the quest map.

Name your bot

It levels up as you play, and gets a new part with every chapter.