Modifying member variables


#1



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 MPG." %(self.color,self.model,str(self.mpg))
    def drive_car(self):
        print self.model
        condition  = "used"
        self.condition = 'used'
my_car = Car("DeLorean", "silver", 88)
print my_car.condition
my_car.drive_car
print my_car.condition  


it gives an error ""Oops, try again. You didn't display the 'used' condition of the car after drive_car(). ""
can anybody help me


#2

def drive_car(self):
         print self.model
         condition  = "used"
         self.condition = 'used'

You don't need first two lines inside of function/method drive_car(self)
Why?


#3

when i put the (print self.model) outside of the method, it gives an erros .it says "self" is not defined


#4

My mistake...

Delete that part and try to run the code.
do reply what you get?


#5

i did what you said , it works thank you


#6

Youre welcome! :slight_smile:


#7

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