7. Creating class methods


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?


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)


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


Now this is happening


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


What do you mean by full sotp?


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


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


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


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