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 - 1Jump! 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
- Store
pip.plan("clean my room")intodoand make an empty listdone. - Use a
whileloop that runs whiletodostill has steps. - Each time,
.pop(0)the next step, printDoing: pick up the socks, and add it todone. - At the end, print
Done 3 of 3!usinglen(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)).
bot.py
Terminal