हिंदी

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,

Advertisements
Advertisements

प्रश्न

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.

कोड लेखन
Advertisements

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 4: Inheritance - EXERCISE [पृष्ठ ८६]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
अध्याय 4 Inheritance
EXERCISE | Q 24. | पृष्ठ ८६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×