7. Creating methods


#1

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

Oops, try again. Make sure your Car class has a display_car() method.

  File "python", line 8
    return "This is a " + self.color + " " + self.model + " with " str(self.mpg) + " MPG"
                                                                     ^
SyntaxError: invalid syntax

Apparently, I'm getting a syntax error, however, I can't seem to find the issue.

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.condition
print my_car.display_car()

#2

Hi @aquaphoenix17,

Regarding the SyntaxError, check this statement for any + operators that may be missing ...

return "This is a " + self.color + " " + self.model + " with " str(self.mpg) + " MPG"

After that is resolved, make sure your output is exactly as specified in the instructions. Every character is significant, including punctuation.


#3

Thanks! I found what I did wrong (missed a "+" and a ".") ... I swear I'm half blind. Anyway, here's my new 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):
        return "This is a " + self.color + " " + self.model + " with " + str(self.mpg) + " MPG."

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

#4