Initializing a class


Hello, i've passed this exercise but its still giving me an error. not quite sure what it means and im looking for clarification.


def __init__(self, model, color, mpg):
       self.model = "DeLorean"
       self.color = "silver"
       self.mpg = 88
    condition = "new"
my_car = Car(model, color, mpg)
print my_car.condition


but what if you now make a second instance, for example your car:

your_car = Car("tardis", "tardis blue", 9999)

It would still be a dolearan, that can't be right. Maybe revisit the exercise where you made init method?


This is what I've changed it to, no errors. Thanks

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg

my_car = Car("DeLorean", "silver", 88)
print my_car.condition


you sorted that out real quick, impressive.


Thanks, Your information helped me sort it out. i figured that if you defined the model and such inside of the class member variable, then i wouldn't need to inside of the init method


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