Bird
Raised Fist0

What is wrong with this availability check snippet?

medium📝 Analysis Q7 of Q15
LLD - Design — Hotel Booking System
What is wrong with this availability check snippet?
availability = {"slot1": True}
if availability.get("slot1") == True:
    print("Available")
else:
    print("Not Available")
AIt fails if slot1 key is missing
BIt always prints 'Available' regardless of value
CIt causes a syntax error
DIt uses wrong comparison operator
Step-by-Step Solution
Solution:
  1. Step 1: Understand get() without default

    availability.get("slot1") returns None if key missing.
  2. Step 2: Compare None to True

    None == True is False, so else branch runs if key missing.
  3. Step 3: Identify problem

    If key missing, code treats as 'Not Available' but no explicit default is set.
  4. Final Answer:

    It fails if slot1 key is missing -> Option A
  5. Quick Check:

    get() without default returns None if missing [OK]
Quick Trick: Always provide default in get() to avoid None [OK]
Common Mistakes:
MISTAKES
  • Assuming get() returns False by default
  • Ignoring None comparison
  • Thinking syntax error occurs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes