Why doesn't this work?
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" %s(self.color, self.model, str(self.mpg)) def drive_car(self): self.condition = "used" class ElectricCar(Car): def __init__(self, battery_type): self.battery_type = battery_type my_car = ElectricCar("Agera", "red", "200", "molten salt")
I get the error in the box:
Traceback (most recent call last):
File "python", line 18, in
TypeError: init() takes exactly 2 arguments (5 given)
And the hint at the bottom:
Oops, try again. my_car does not appear to be an instance of ElectricCar.
I have looked for solutions on the forum, but no one appears to have one yet that doesn't involve simply duplicating all the info in the Cars class, in the ElectricCars class. This appears to me to be the wrong way to do it, as, what's the point of inheritance if you have to duplicate everything anyway? (and yes I know the indenting is off in the example above, for some reason the quotes kill the indenting)