Inheritance


#1

Oops, try again. Make sure you've defined a new ElectricCar class after defining Car.

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 " + self.color +" "+ self.model + " with " + str(self.mpg) + " MPG."
    def drive_car(self):
        self.condition = "used"
        
class EletricCar(Car):
    def __init__(self, model, color, mpg, battery_type):
        super(EletricCar, self).__init__(model,color,mpg)
        self.battery_type = battery_type
        
my_car = EletricCar("DeLorean", "silver", 88, "molten salt")

#2

Although you code isn't well formatted, you should make sure you are not missing the double underscores before and after init.

Also, you should be swapping these lines:

and return the function with this line.

which is now at the end of the function.

I hope this helps! :wink:


#3

Make sure you've defined a new ElectricCar class after defining Car.
why its giving this error message


#4

@dasanan, you misspelled ElectricCar in all cases, correct it.

@bayoishola20, the __ dissapear if no markup is used. and don't understand this:

what does that mean?


#5

Yeah, I know it will disappear that's why I started with "well formatted".

Any issue with using the return keyword to return the function? Or...???


#6

Thank you for formatting your code. With the addition @stetim94 made, are you okay now? :wink:


#7

again, what? which return? dasanan used super() to call the parent init method, which is perfectly valid (and done correctly)


#8

Okay! :no_mouth: :no_mouth:


#9

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