6. Referring to member variables


#1

When I paste the following code into my own IDE it prints out just what the question aks for. However, I couldn't pass the task because it raises an error message:

You need to pass three arguments when creating a Car().

Please can someone help xx

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
print my_car.model 
print my_car.color
print my_car.mpg


#2

It does not throw any error! ( I just tested it)
Can you clarify more?

Hint**
copy this same code of yours and try to run!


#3

yh it works, thnx a lot! Not shown in this post, but I added some comments with # to help me remembering the task; now that i've deleted them, it works perfectly


#4

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