Bird
0
0

Find the bug in this code snippet:

medium📝 Debug Q7 of 15
Agentic AI - Real-World Agent Applications
Find the bug in this code snippet:
skills = {}
def add_skill(name, func):
    skills[name] = func
add_skill("reminder", lambda: print("Reminder set"))
skills["reminder"]()
ANo bug; code runs and prints correctly.
BLambda function missing parentheses in call.
Cskills dictionary is not initialized.
DFunction add_skill does not add skills properly.
Step-by-Step Solution
Solution:
  1. Step 1: Check dictionary initialization

    Skills dictionary is initialized as empty before adding skills.
  2. Step 2: Verify function and call

    add_skill adds the lambda function correctly; calling skills["reminder"]() executes the print.
  3. Final Answer:

    No bug; code runs and prints correctly. -> Option A
  4. Quick Check:

    Bug presence = None [OK]
Quick Trick: Check initialization and function calls carefully [OK]
Common Mistakes:
  • Assuming missing parentheses in lambda call
  • Overlooking dictionary initialization
  • Misunderstanding function behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes