Overriding Methods


#1

What is wrong with the Code - giving error -Oops, try again. It looks like you didn't update the condition of my_car to 'like new'.

class Car(object):
condition = "new"
def init(self, model, color, mpg):
self.model = model
self.color = color
self.mpg = mpg
def display_car(self):
return "This is a %s %s with %s MPG." %(self.color,self.model,str(self.mpg))

class ElectricCar(Car):
def init(self,model,color,mpg,battery_type):
Car.init(self,model,color,mpg)
self.battery_type = battery_type
def drive_car(self):
self.condition = "Like new"

my_car =ElectricCar("DeLorean","silver",88,"molten salt")

print (my_car.condition)
print my_car.drive_car()
print my_car.condition


#2

resolved ---
there was a type in setting the new value for the condition --("Like new")

correct one is as mentioned below

self.condition = "like new"