Bird
0
0

Given this agent code:

medium📝 Predict Output Q5 of 15
Agentic AI - Future of AI Agents
Given this agent code:
class Agent:
    def __init__(self):
        self.memory = []
    def act(self, input):
        self.memory.append(input)
        return len(self.memory)

agent = Agent()
print(agent.act('a'))
print(agent.act('b'))
print(agent.memory)

What is the output?
A1\n2\n['a', 'b']
B0\n1\n['a', 'b']
C1\n1\n['a']
DError: memory is not defined
Step-by-Step Solution
Solution:
  1. Step 1: Understand memory list updates

    Each act call appends input to memory, increasing its length.
  2. Step 2: Trace outputs

    First call returns 1, second returns 2, memory contains ['a', 'b'].
  3. Final Answer:

    1\n2\n['a', 'b'] -> Option A
  4. Quick Check:

    Memory grows with inputs = 1, 2, ['a', 'b'] [OK]
Quick Trick: List append grows memory, length returns count [OK]
Common Mistakes:
  • Forgetting to append input
  • Confusing length with last element
  • Assuming memory resets each call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes