Bird
0
0

Find the bug in this message processing code:

medium📝 Debug Q7 of 15
Agentic AI - Future of AI Agents
Find the bug in this message processing code:
def process_message(msg):
    print(msg["sender"])
    print(msg["receiver"])

message = {"sender": "AgentA", "content": "Data"}
process_message(message)
AFunction process_message is not defined
BKey 'receiver' missing in message dictionary
Cprint statements have syntax errors
DMessage dictionary keys are misspelled
Step-by-Step Solution
Solution:
  1. Step 1: Check keys accessed in function

    process_message tries to print msg["receiver"], but message lacks this key.
  2. Step 2: Identify the error caused

    Accessing a missing key causes a KeyError at runtime.
  3. Final Answer:

    Key 'receiver' missing in message dictionary -> Option B
  4. Quick Check:

    Missing key access causes KeyError [OK]
Quick Trick: Ensure all accessed keys exist in dictionaries [OK]
Common Mistakes:
  • Assuming all keys are present
  • Thinking function is undefined
  • Confusing syntax errors with runtime errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes