Bird
0
0

Given this snippet:

medium📝 Analysis Q14 of 15
LLD - Design — Food Delivery System

Given this snippet:
assigned_agent = None
for agent in agents:
  if agent.status = 'free':
    assigned_agent = agent
return assigned_agent

What is the main error in this code?

AReturning assigned_agent inside the loop
BNot initializing assigned_agent before loop
CUsing assignment operator '=' instead of comparison '==' in if condition
DUsing 'free' instead of 'available' as status
Step-by-Step Solution
Solution:
  1. Step 1: Check the if condition syntax

    The condition uses '=' which assigns value instead of '==' which compares values.
  2. Step 2: Understand impact of wrong operator

    This causes a syntax error or unintended behavior because '=' cannot be used in conditions.
  3. Final Answer:

    Using assignment operator '=' instead of comparison '==' in if condition -> Option C
  4. Quick Check:

    Use '==' for comparison, not '=' [OK]
Quick Trick: Use '==' for comparisons in conditions [OK]
Common Mistakes:
  • Confusing '=' with '==' in if statements
  • Thinking assigned_agent must be initialized inside loop
  • Assuming return inside loop is the error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes