0%
⭐ 0 XPMap
Chapter 6 · Quest 3 of 4 · 10 XP

Pass the Baton

🏃 In a relay, each runner passes the baton to the next. In a team of agents, each one does its part and says who goes next: that's a handoff. A function can return two things at once:

def coin():
    return "heads", 1

side, points = coin()
print(side, points)
heads 1

Three agents are ready in the editor: a writer, an editor and a publisher. Each takes the text, changes it, and returns the new text plus the next agent's name. The publisher hands off to "done".

Instructions

  1. Start with text = "a robot learns to dance" and agent = "writer".
  2. Loop while agent != "done": print Now: writer (the current agent), then run AGENTS[agent](text) and store the two things it returns back in text and agent.
  3. After the loop, print the final text.
💡 Hint

The key line is text, agent = AGENTS[agent](text). It runs the agent and catches both things it hands back.

Ask the community

bot.py
Terminal
← BackNext →

Chapter 6: Party of Agents

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.