Bird
0
0

The following code is intended to add error handling to a production agent's run method:

medium📝 Debug Q14 of 15
Agentic AI - Production Agent Architecture
The following code is intended to add error handling to a production agent's run method:
class Agent:
    def __init__(self):
        self.modules = ['perception', 'planning', 'execution']
    def run(self):
        for module in self.modules:
            try:
                print(f"Running {module} module")
            except Exception as e:
                print(f"Error in {module}: {e}")
agent = Agent()
agent.run()
What is the error in this code?
Aself.modules is not defined
BIndentation error in the for loop
CMissing colon after except Exception as e
Dprint statement syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of try-except block

    The except line is missing a colon at the end, which is required in Python syntax.
  2. Step 2: Verify other parts of the code

    Indentation is correct, self.modules is defined, and print statements use correct syntax.
  3. Final Answer:

    Missing colon after except Exception as e -> Option C
  4. Quick Check:

    Colon needed after except line = A [OK]
Quick Trick: Look for missing colons in try-except blocks [OK]
Common Mistakes:
  • Assuming indentation is wrong
  • Thinking self.modules is undefined
  • Confusing print syntax with error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes