7. Creating class methods


#1



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

But I did pass it. Or did I? What am I doing wrong?

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


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

the beauty of init is that you have access to all the variables thanks to self, which means you display car can simply look like this:

def display_car(self):

which means you can just call display car method (since you created an instance of your object):

print my_car.display_car()

#3

Now this is happening


#4

you miss the full stop after MPG. strings printed/returned generally have to be an exact match


#5

What do you mean by full sotp?


#6

according to a dictionary:
full stop:
a punctuation mark (.) used at the end of a sentence or an abbreviation.

there is this thing called google (among others) which you can use if you don't know a word


#7

You mean I should put a full stop after the str(self.mpg)? I'm not following it


#8

the string which is returned should be an exact match, as you can see in the error message at the end of the string is a full stop. In your string, there is not


#9

YES! OF COURSE! I didn't see that until you pointed it out. Thanks for the help


#10