Initializing a class


#1

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

Car(object):

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



#2

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?


#3

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

#4

you sorted that out real quick, impressive.


#5

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


#6

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