Creating Class Methods


Oops, try again. It looks like you didn't print "This is a silver DeLorean with 88 MPG.".

It prints what is expected.
This is a silver DeLorean with 88 MPG.

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

my_car = Car("DeLorean", "silver", 88)


Perhaps you're expected to create a string and print it all at once, as opposed to printing multiple strings. The output would be the same but may look different to codecademy due to a hackish approach to monitoring output


Thanks for your response.

I tried the following too.

def display_car(self):
        print "This is a", 
        print self.color, 
        print self.model, 
        print "with", 
        print str(self.mpg), 
        print "MPG.

def display_car(self):
        print "This is "+ self.color+" "+ self.model+ " with " + str(self.mpg) + " MPG."

None of the above works. I understand the problem with codeacademy's approach. I just want to get to the next step!


That prints a slightly different string.


Okay, but none of the three gets me past to the next step. What is the right print command?


After reviewing your code it appears that you are missing the "a" after "This is" in your print string statement and also the "G" in "MPG" at the end of the statement. The code below worked for me.

def display_car(self):
print "This is a " + self.color + " " + self.model + " with " + str(self.mpg) + " MPG."


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