Overriding methods


#1



error coming again and again
new
none
new
none
any help will be appreciable


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):
        super(ElectricCar,self).__init__(model,color,mpg)
        self.battery_type=battery_type
    def drive_car(self):
        condition="like new"
my_car = ElectricCar("foo","silver",88,"molten salt")     
print my_car.condition
my_car.drive_car()
print my_car.condition


#2

here:

condition="like new"

condition has a local variable scope (it only exist inside the drive_car method)

You need to update the class/member variable, maybe you can check this exercise or the drive_car method of Car class for inspiration


#3

thnx for you kind help


#4