Bird
0
0

Identify the issue in the following availability check code:

medium📝 Analysis Q6 of 15
LLD - Design — Hotel Booking System
Identify the issue in the following availability check code:
availability = {"slotA": True}
if availability["slotB"]:
    print("Available")
else:
    print("Not Available")
AThe code will print 'Available' regardless of dictionary content
BKeyError occurs because 'slotB' is not in the dictionary
CThe dictionary keys are case-insensitive, so no error
DThe else block will never execute
Step-by-Step Solution
Solution:
  1. Step 1: Accessing dictionary key 'slotB'

    Since 'slotB' is not present in availability, direct access causes KeyError.
  2. Step 2: Understand dictionary behavior

    Using [] for missing keys raises KeyError; get() method avoids this.
  3. Final Answer:

    KeyError occurs because 'slotB' is not in the dictionary -> Option B
  4. Quick Check:

    Direct dict access missing key causes KeyError [OK]
Quick Trick: Direct dict access missing key throws KeyError [OK]
Common Mistakes:
  • Assuming missing keys return False or None
  • Thinking dictionary keys are case-insensitive

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes