Creating Clas* methods


#1



https://www.codecademy.com/courses/python-intermediate-en-egNXj/1/1?curriculum_id=4f89dab3d788890003000096#

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

i thought that the code works normally as it works as it prints out what i needed to print but it just gave me the error message above as well as the correct thing.
*I WOULD HAVE SPELT THE TITLE AS CLASS BUT IT DOESN'T LET ME


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):
        return "this is a %s %s with %s MPG"%(self.color, self.model,str(self.mpg))

my_car = Car("DeLorean", "silver", 88)
print my_car.display_car("DeLorean","silver",88)


#2

in __init__() you make the variable accessible through self, so you don't have to pass model, color and mpg as parameter in display_car method. You can access this variables through self


#3

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