Inheritance Problem


Hi please I need help with my code and a bit of more explanation and thanks.

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
#print my_car.condition

class ElectricCar(Car):
    def __init__(self,battery_type,model,color,mpg):
        self.battery_type = battery_type
my_car = ElectricCar("Toyota","Black",55,"molten salt")
print my_car.display_car()

9. Inheritance - Unsure
9. Inheritance - Unsure

Hi @coursejumper28708,

The parameters in function and method headers must be in the order that is expected. You have this in the ElectricCar definition ...

    def __init__(self,battery_type,model,color,mpg):

Codecademy is expecting this ...

    def __init__(self, model, color, mpg, battery_type):

Correct and consistent spelling of variables is also essential. You have ...


That should be ...

        super(ElectricCar,self).__init__(model, color, mpg)


It worked just one more question.
is super(ElectricCar,self).init(model,color,mpg) the same as this
then you know initialize them one by one ?


They both accomplish the same result. The first one is more concise since it utilizes some of the work that you did in the __init__ method for the Car class.