Bird
0
0

Given this code snippet for scaling agents horizontally, what will be the output?

medium📝 Predict Output Q13 of 15
Agentic AI - Production Agent Architecture
Given this code snippet for scaling agents horizontally, what will be the output?
class Agent:
    def __init__(self, id):
        self.id = id
    def run(self):
        print(f"Agent {self.id} running")

agents = [Agent(i) for i in range(3)]
for agent in agents:
    agent.run()
AAgent 3 running
BAgent running\nAgent running\nAgent running
CNo output, code has error
DAgent 0 running\nAgent 1 running\nAgent 2 running
Step-by-Step Solution
Solution:
  1. Step 1: Understand the Agent class and its run method

    The run method prints the agent's id with the message "Agent {id} running".
  2. Step 2: Analyze the loop over agents

    There are 3 agents with ids 0, 1, 2. The loop calls run() on each, printing their messages in order.
  3. Final Answer:

    Agent 0 running Agent 1 running Agent 2 running -> Option D
  4. Quick Check:

    Each agent prints its id running [OK]
Quick Trick: Each agent prints its id in order [OK]
Common Mistakes:
  • Thinking all agents print the same message without id
  • Assuming only one agent runs
  • Believing code has syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes