0%
⭐ 0 XPMap
Chapter 5 · Quest 4 of 5 · 10 XP

Treasure Hunt

🗺️ Real agents work in a loop: look, think, act. Look at the world, decide a move, make it, look again. Your bot stands on a treasure map at x = 0, y = 0. Each time it calls look(x, y), the map says which way to go:

look(0, 0)  # "east": add 1 to x
look(3, 0)  # "north": add 1 to y
look(3, 2)  # "treasure"!

Your bot doesn't know where the treasure is. It just follows what it sees, and it stops after 20 moves so it never wanders forever. The checker hides the treasure somewhere else too.

Instructions

  1. Start at x = 0 and y = 0.
  2. Loop up to 20 times: look(x, y), and move 1 step for "east", "west", "north" or "south".
  3. When it says "treasure", print Found the treasure at 3, 2! with the real x and y, and stop.
💡 Hint

east is x = x + 1, west is x = x - 1, north is y = y + 1, south is y = y - 1. Check for treasure first, print, then break.

Ask the community

bot.py
Terminal
← BackNext →

Chapter 5: Loops and Plans

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.