Bird
0
0

Identify the error in the following Booking class code snippet:

medium📝 Analysis Q14 of 15
LLD - Design — Hotel Booking System
Identify the error in the following Booking class code snippet:
class Room:
    def __init__(self, number):
        self.number = number
        self.is_available = True

class Booking:
    def __init__(self, room, guest):
        self.room = room
        self.guest = guest
    def book(self):
        if self.room.is_available:
            self.room.is_available = False
            print("Booking successful")
        else:
            print("Room not available")

room = Room(201)
booking = Booking(room)
booking.book()
Ais_available should be a method, not attribute
BMissing guest argument when creating Booking instance
Cbook method should return a value
DRoom class is not defined
Step-by-Step Solution
Solution:
  1. Step 1: Check Booking constructor parameters

    Booking __init__ requires room and guest, but only room is passed when creating booking instance.
  2. Step 2: Identify missing argument error

    Omitting guest argument causes a TypeError at runtime.
  3. Final Answer:

    Missing guest argument when creating Booking instance -> Option B
  4. Quick Check:

    Constructor args mismatch = missing guest [OK]
Quick Trick: Match all constructor parameters when creating objects [OK]
Common Mistakes:
  • Ignoring missing guest argument
  • Assuming book method must return value
  • Thinking is_available must be a method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes