Inheritance


#1



https://www.codecademy.com/courses/python-intermediate-en-egNXj/1/3

When I hit the button "Save and Submit Code" it gives me the phrase "Oops, try again". What should I do to pass the lesson?


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, self.mpg)
        
    def drive_car(self):
        self.condition = "used"

my_car = Car("DeLorean", "silver", 88)
print my_car.condition
my_car.drive_car()
print my_car.condition

class ElectricCar(Car):
    def __init__(self, model, color, mpg, battery_tape):
        self.model = model
        self.color = color
        self.mpg = mpg
        self.battery_type = battery_type
my_car = ElectricCar("BMW", "grey", 40, "molten salt")


#2

It is quite possible the exercise wants our ElectricCar to inherit the base parameters from the parent (super) class, rather than instantiate them locally. Think on this for a minute and see if there is some way to do this.


#3

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