In: Computer Science
Python code:
class House():
valuationRate = 10
def __init__(self,city,sqft,price):
self.city = city
self.sqft = sqft
self.price = price
def getPrice(self):
return self.price
def applyValuation(self):
self.price += self.price * self.valuationRate/100
#Townhouse class inherited from class House
class Townhouse(House):
#ValuationRate of 5
valuationRate = 5
def __init__(self,city,sqft,price):
House.__init__(self,city,sqft,price)
def setPrice(self,price):
self.price = price
#Creating object of house
obj1 = House("Atlanta",10000,200000)
#Creating object of Townhouse
obj2 = Townhouse("Norcross",5000,100000)
obj2.setPrice(200000)
obj1.applyValuation()
obj2.applyValuation()
print("Price of House object is $",obj1.price)
print("Price of Townhouse object is $",obj2.price)
Please refer code screenshot for indentation:
Output: