Bird
0
0

Which of the following Python code snippets correctly implements an agent class with a method that returns a fixed action?

easy📝 Syntax Q3 of 15
Agentic AI - Future of AI Agents
Which of the following Python code snippets correctly implements an agent class with a method that returns a fixed action?
Aclass Agent: def act(self): return 'move_forward'
Bclass Agent: def act(self): print('move_forward')
Cclass Agent: def act(self): self.action = 'move_forward'
Dclass Agent: def act(self): return self.action
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    The agent class should have an act method that returns a fixed action string.
  2. Step 2: Analyze options

    class Agent: def act(self): return 'move_forward' returns the string directly, which is correct. class Agent: def act(self): print('move_forward') prints instead of returning. class Agent: def act(self): self.action = 'move_forward' assigns but does not return. class Agent: def act(self): return self.action returns an undefined attribute.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Method returns action string [OK]
Quick Trick: Return action string directly in act method [OK]
Common Mistakes:
  • Using print instead of return
  • Assigning action without returning
  • Returning undefined attributes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes