I don't know what is wrong: 7/11


My code:

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self, model, color, mpg):
        print "This is a " + str(self.model) + " " + str(self.color) + " with " + str(self.mpg) + " MPG"

my_car = Car("DeLorean", "silver", 88)
print my_car.condition
my_car.display_car(my_car.color, my_car.model, my_car.mpg)

error msg: Oops, try again. Make sure you pass the self keyword to the display_car() method.

but code prints "new
This is a DeLorean silver with 88 MPG
None" and it is correct!


self is the owner instance with all the properties in its scope. We do not need to include them in the definition parameters.

def display_car(self):


Try setting display_car to return instead of print and then use
print my_car.display_car(my_car.color, my_car.model, my_car.mpg)


But then:


No, then same error :confused:


The only parameter that is not a string is self.mpg. The others do not need to be converted.

Now looking at your last line, the call to my_car.display_car() takes no arguments.


okay but how can I solve this?




Thank you! :smile: Now it is correct!


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