9. Inheritance pls


#1




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

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


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.drive_car()

print my_car.condition

class ElectricCar(Car):
    def __init__(self, model, color, mpg, battery_type):
        Car.__init__(self, model, color, mpg, "new")
        self.battery_type = battery_type        
my_car = ElectricCar("BMW", "silver", 150, "molten salt")
print my_car

Can someone help me with the code? I read about 8 posts on this subject and couldn't find the answear :confused:


#2

here:

Car.__init__(self, model, color, mpg, "new")

why do you pass "new" as argument?

condition is a member variable, it has no part in __init__()


#3

:gift: Thank you :joy:


#4