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


#1

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!


#2

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):

#3

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)


#4

But then:


#5

No, then same error :confused:


#6

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.


#7

okay but how can I solve this?


#8

    my_car.display_car()

#9

Thank you! :smile: Now it is correct!


#10

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