Bird
0
0

Identify the error in this personal assistant agent code:

medium📝 Debug Q6 of 15
Agentic AI - Real-World Agent Applications
Identify the error in this personal assistant agent code:
def add_task(task):
    tasks.append(task)
tasks = []
add_task("call")
print(tasks)
Atasks is not defined before append.
BIndentation error in function definition.
CFunction add_task missing return statement.
DNo error; code runs correctly.
Step-by-Step Solution
Solution:
  1. Step 1: Check variable initialization

    Variable 'tasks' is defined as an empty list before function call.
  2. Step 2: Verify function behavior

    Function appends 'call' to tasks list; no errors occur.
  3. Final Answer:

    No error; code runs correctly. -> Option D
  4. Quick Check:

    Code correctness = No error [OK]
Quick Trick: Define variables before use to avoid errors [OK]
Common Mistakes:
  • Assuming missing return causes error
  • Confusing variable scope
  • Overlooking correct indentation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes