6. Referring to member variables


#1




I don't know what i'm doing wrong . Error message looks like this :
Oops, try again. The model of my_car should be "DeLorean".


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


#2

And if you print out that attribute, what is the result?


#3

result is correct i guess :
new
88
silver
DeLorean
None


#4

really?

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

looks what the model is (what is printed)


#5

but you can do better than guessing, so do that

You find things like this by repeatedly ruling causes out. If you do this carefully you can find the problem pretty quickly. If you guess while doing this, then it's likely that some of the guesses are wrong and you'll get nowhere


#6

wtf how that possible ?


#7

That's what you'd find out next. Follow where that value should have been coming from and check along the way if it's the one you want or not until you've found the place where you lost track of it


#8

oh i know why is print 88
because of the position of argument "mpg"


#9

Thank you guys . I just find the solution .


#10

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