Inheritance


#1



https://www.codecademy.com/courses/python-intermediate-en-egNXj/1/3?curriculum_id=4f89dab3d788890003000096#


Oops, try again. my_car does not appear to be an instance of ElectricCar


I don't understand what am I doing wrong. I've gone through the messages on the forums, and used the super() method although it wasn't theoretically introduced yet, and the code is still not working. any ideas?


class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        print "This is a %s %s with %s 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):
        super(ElectricCar,self).__init__(model, color, mpg)   
        self.battery_type = battery_type
        
my_car = ElectricCar("DeLorean", "silver", 88, "molten salt")


#2

check the name of ElectricCar class constructor.

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

#3

ok I understood what was wrong. It was just a matter of following the instructions of the Lesson.
I used this code and it worked:

class ElectricCar(Car):
    battery_type=""
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
        
my_car = ElectricCar("DeLorean", "silver", 88)
my_car.battery_type = "molten salt"

#4

I think you made a misspelling mistake, __init__ and __Init__ ? any difference ?


#5

oh! that's true.
didn't notice that. now the first code works as well.
thanks!


#6

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