Bird
0
0

Given the following code, what will be the output?

medium📝 Analysis Q13 of 15
LLD - Design — Hotel Booking System
Given the following code, what will be the output?
booked_slots = {"9AM": True, "10AM": False}
requested_slot = "10AM"
if not booked_slots.get(requested_slot, False):
    print("Slot Available")
else:
    print("Slot Booked")
ASlot Available
BSlot Booked
CKeyError
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the dictionary and requested slot

    booked_slots maps times to True (booked) or False (free). "10AM" is False, meaning free.
  2. Step 2: Evaluate the condition

    booked_slots.get("10AM", False) returns False. 'not False' is True, so it prints "Slot Available".
  3. Final Answer:

    Slot Available -> Option A
  4. Quick Check:

    False means free, so output is Slot Available [OK]
Quick Trick: False means free slot, so print available [OK]
Common Mistakes:
  • Assuming True means available instead of booked
  • Expecting KeyError when key exists
  • Ignoring default value in get()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes