Advertisements
Advertisements
Question
Define a class furniture in Python with the given specifications:
Instance variables:
→ Type
→ Model
Methods
→ getType() To return instance variable Type
→ getModel()To return instance variable Model
→ show() To print instance variable Type and Model
Define a class sofa:
→ No_of_seats
→ Cost
Methods
→ getSeats() To return instance variable No_of_seats
→ getCost() To return instance variable Cost
→ show() To print instance variable No_of_seats and Cost
This class inherits class furniture
Code Writing
Definition
Advertisements
Solution
class Furniture(object):
def __init__(self, furniture_type, model):
self.type = furniture_type
self.model = model
def getType(self):
return self.type
def getModel(self):
return self.model
def show(self):
print("Type:", self.type)
print("Model:", self.model)
class Sofa(Furniture):
def __init__(self, furniture_type, model, no_of_seats, cost):
super().__init__(furniture_type, model)
self.no_of_seats = no_of_seats
self.cost = cost
def getSeats(self):
return self.no_of_seats
def getCost(self):
return self.cost
def show(self):
super().show()
print("Number of seats:", self.no_of_seats)
print("Cost:", self.cost)
shaalaa.com
Is there an error in this question or solution?
