Inheritance Problem


#1

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

class ElectricCar(Car):
    def __init__(self,battery_type,model,color,mpg):
        super(ElectricCar,self).__init__(mpdel,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
#2

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 ...

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

That should be ...

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

#3

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


#4

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.


#5