Bird
0
0

Which of the following code snippets correctly checks if a room is available given a list of booked rooms booked_rooms = [101, 102, 103] and a requested room requested_room = 104?

easy📝 Conceptual Q12 of 15
LLD - Design — Hotel Booking System
Which of the following code snippets correctly checks if a room is available given a list of booked rooms booked_rooms = [101, 102, 103] and a requested room requested_room = 104?
Aif requested_room in booked_rooms: print('Available')
Bif requested_room == booked_rooms: print('Available')
Cif requested_room not in booked_rooms: print('Available')
Dif requested_room > booked_rooms: print('Available')
Step-by-Step Solution
Solution:
  1. Step 1: Understand the list and requested room

    booked_rooms contains rooms already taken: 101, 102, 103. requested_room is 104.
  2. Step 2: Check correct condition for availability

    Room is available if requested_room is NOT in booked_rooms. So, 'if requested_room not in booked_rooms' is correct.
  3. Final Answer:

    if requested_room not in booked_rooms: print('Available') -> Option C
  4. Quick Check:

    Not in booked_rooms means available [OK]
Quick Trick: Check 'not in' to confirm availability [OK]
Common Mistakes:
  • Using 'in' instead of 'not in' to check availability
  • Comparing equality of a number to a list
  • Using greater than operator on list

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes