Calling a child class


10. overriding methods

Traceback (most recent call last):
File "python", line 29, in
TypeError: drive_car() takes no arguments (1 given)

I don't see how I am giving it an argument? Is it the object "my_car" that is the argument?
ot sure how to call this method

Replace this line with your 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):
        return "This is a %s %s with %s MPG" % (self.color, self.model, self.mpg)
    def drive_car(self):
        self.condition = "used"
class ElectricCar(Car):
    def __init__(self, model, color, mpg, battery_type):
        Car.__init__(self, model, color, mpg)
        self.battery_type = battery_type
    def drive_car():
        condition = "like new"

my_car = Car("DeLorean", "silver", 88)
my_car = ElectricCar("Volvo", "black", 30, "molten salt")

print my_car.condition


print my_car.condition


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