0%
⭐ 0 XPMap
Chapter 5 · Quest 5 of 5 · 15 XP

Double-Check

✅ Even smart models make mistakes. Good agents check their own work and try again. Pip's solve() is a bit sloppy: its first try is off by one.

import pip
print(pip.solve("What is 17 plus 25?", 1))
print(pip.solve("What is 17 plus 25?", 2))
43
42

pip.parse(question) pulls the numbers and the sum out of a question, like (17, 25, "+"). A * unpacks it into your calculator: calc(*(17, 25, "+")) is calc(17, 25, "+"). So your bot can work it out itself and compare. Finish it for the Strategist badge.

Instructions

  1. Make verify(question, answer) that returns True if answer matches calc(*pip.parse(question)).
  2. Make careful(question) that tries pip.solve(question, attempt) for attempts 1 to 3 and returns the first answer that passes verify.
  3. For a wrong try, print Attempt 1 was wrong, trying again.
  4. Print careful("What is 17 plus 25?").
💡 Hint

verify is one line: return answer == calc(*pip.parse(question)). In careful: for attempt in range(1, 4), and return as soon as verify says True.

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.