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 %i MPG." %(self.color,self.model,self.mpg)     
        
    def drive_car(self):
        self.condition = "used"
        


my_car = Car("DeLorean", "silver", 88)     

print my_car.drive_car()

my_car.drive_car()

print my_car.drive_car()


#2

it is giving error Oops, try again. You should get the condition of my_car using my_car.condition


#3

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



print my_car.condition

my_car.drive_car()


        
print my_car.condition

i was printing the method and not printing the variable...
:slight_smile::joy:


#4

I almost lost and drown. I didn't read the finally instruction. :wink:


#5

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