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
- Start with
text = "a robot learns to dance"andagent = "writer". - Loop
while agent != "done": printNow: writer(the current agent), then runAGENTS[agent](text)and store the two things it returns back intextandagent. - 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.
bot.py
Terminal