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

Step by Step

👣 A plan is only words until someone does it. An agent works through its plan in a while loop: it keeps going while there's work left.

energy = 3
while energy > 0:
    print("Jump!")
    energy = energy - 1
Jump!
Jump!
Jump!

Each time round, something must change, or the loop runs forever. Here .pop(0) takes the first item off a list and hands it to you, so the list gets shorter each time.

Instructions

  1. Store pip.plan("clean my room") in todo and make an empty list done.
  2. Use a while loop that runs while todo still has steps.
  3. Each time, .pop(0) the next step, print Doing: pick up the socks, and add it to done.
  4. At the end, print Done 3 of 3! using len(done).
💡 Hint

while len(todo) > 0: then step = todo.pop(0), print("Doing: " + step) and done.append(step). After the loop, build the last line with str(len(done)).

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.