I'm not getting any errors. My question is this - what's the point of Inheritance when I still have to type out the bits such as "self.model = model" ? Take a look at the code starting at "class ElectricCar(Car):" --- by inheriting Car(), why doesn't it actually inherit the code that I've already entered for Car()?
Sorry if this seems trivial or if I am missing the point, but I don't see the benefit of inheritance if I still have to tell the new class what everything means, when I already told its parent what it means.
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, str(self.mpg)) def drive_car(self): self.condition = "used" class ElectricCar(Car): def __init__(self, model, color, mpg, battery_type): self.model = model self.color = color self.mpg = mpg self.battery_type = battery_type my_car = ElectricCar("Prius", "Gold", 0, "molten salt")
Replace this line with your code.