Bird
Raised Fist0

What will be the output of this code?

medium📝 Analysis Q5 of Q15
LLD - Design — Hotel Booking System
What will be the output of this code?
class Hotel:
    def __init__(self):
        self.rooms = []
    def add_room(self, room):
        self.rooms.append(room)

hotel = Hotel()
room1 = 'Room101'
hotel.add_room(room1)
print(len(hotel.rooms))
A0
B1
CError
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand Hotel initialization

    Hotel starts with an empty list rooms.
  2. Step 2: Add room1 to rooms list

    room1 string is appended to rooms list.
  3. Step 3: Print length of rooms list

    Length is 1 because one item was added.
  4. Final Answer:

    1 -> Option B
  5. Quick Check:

    Rooms list length after add = 1 [OK]
Quick Trick: Appending one room increases list length to 1 [OK]
Common Mistakes:
MISTAKES
  • Assuming rooms list remains empty
  • Expecting error due to string instead of object
  • Confusing print output with None

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes