Advertisements
Advertisements
Question
SKP Hotel offers accommodation, meals facilities.
→ Create a class Accommodation with Room Number, type of room, and rent, etc..
→ Create a class meals services includes: meals code, name, price, etc..
→ Create a class customer with customer number, name, address, etc.
→ Customer class is derived by using Accommodation and meals classes.
Code Writing
Advertisements
Solution
class Accommodation(object):
def get_room(self):
self.room_no = input("Room number: ")
self.room_type = input("Type of room: ")
self.rent = float(input("Room rent: "))
class Meals(object):
def get_meal(self):
self.meal_code = input("Meal code: ")
self.meal_name = input("Meal name: ")
self.meal_price = float(input("Meal price: "))
class Customer(Accommodation, Meals):
def get_customer(self):
self.customer_no = input("Customer number: ")
self.customer_name = input("Customer name: ")
self.address = input("Address: ")
self.get_room()
self.get_meal()
def display(self):
print("\nCustomer number:", self.customer_no)
print("Customer name:", self.customer_name)
print("Address:", self.address)
print("Room number:", self.room_no)
print("Room type:", self.room_type)
print("Room rent:", self.rent)
print("Meal code:", self.meal_code)
print("Meal name:", self.meal_name)
print("Meal price:", self.meal_price)
c = Customer()
c.get_customer()
c.display()
Customer inherits from both Accommodation and Meals; therefore, this is multiple inheritance.
shaalaa.com
Is there an error in this question or solution?
