9.Inheritance please help, many thanks!


#1




Traceback (most recent call last):
File "python", line 24, in
TypeError: init() takes exactly 4 arguments (5 given)


help, guys. i don't see what's wrong. I know I could use super, but what's wrong with this code?


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, str(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 __inti__(self, model, color, mpg, battery_type):
        self.model = model
        self.color = color
        self.mpg   = mpg
        self.battery_type = battery_type

my_car = ElectricCar('Ecar','blue', 99, "molten salt")


Inheritance
#2

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

you spelt __init__ wrong.


#3

OMG, totally missed it, many thanks!


#4

No problem!


#5

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