Creating class methods


#1

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):
            return "This is  %s %s with %s mpg" % \ 
            (self.color, self.model, self.mpg)
        
my_car = Car("DeLorean", "silver", 88)
print my_car.display_car()

File "python", line 9
return "This is %s %s with %s mpg" % \
^
SyntaxError: unexpected character after line continuation character

Error is self explanatory but I can't get it out of the way


#2

HI you should put the method display_car() inside the class Car() instead of inside the __int__() .
and here

return "This is  %s %s with %s mpg" % \ 
            (self.color, self.model, self.mpg)

the string you should print is that

"This is a [color] [model] with [mpg] MPG."

#3

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