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
- Make
verify(question, answer)that returnsTrueifanswermatchescalc(*pip.parse(question)). - Make
careful(question)that triespip.solve(question, attempt)for attempts 1 to 3 and returns the first answer that passesverify. - For a wrong try, print
Attempt 1 was wrong, trying again. - 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.