I pass the exercise but I still think there is a repetition in my code

less code than I have wrote dry : don't repeat yourself

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("VW", "white", 0, "molten salt")


there is, to reduce your code you could use super() to call parent __init__() method, that would reduce your code.

you could also give a named argument to your init of Car:

class Car(object):
     def __init__(self, model, color, mpg, battery_type=None):

then ElectricCar doesn't need a init method, so Cars init method is called automatically.


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