10. Overriding methods


#1



10. Overriding methods


Hello guys,

I'm having trouble with my code and have no idea, what I have done wrong. I get this error message:
Oops, try again. It looks like you didn't update the condition of my_car to 'like new'.

I would be glad if someone could help.


Replace this line with your code. 
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 %d MPG." %(self.color, self.model, self.mpg)
        
    def drive_car(self):
        self.condition = "used"

class ElectricCar(Car):
    
    def __init__(self, model, color, mpg, battery_type):
        self.model = model
        self.color = color
        self.mpg   = mpg        
        self.battery_type = battery_type  
    
    def drive_car(self):
        self.condtion = "like new"

my_car = ElectricCar("Tesla", "silver", 0, "molten salt")
print my_car.condition
my_car.drive_car()
print my_car.condition


#2

Typo in your drive car method.


#3

Thank you very much! I was already getting desperate =D


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.