I printed it correct, and it tells me I didnt print it? HELP


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

Replace this line with your code.




Hi! In the first lesson of introduction to classes, it explains how to print using this a little bit better. You have two options. You can write them into your code like you tried to do, but what the problem is, is that you added self.color, self.model as one thing. You need to add them separately, and add the comma separately as well like "This is a " + self.color + ", " + self.model + ...
The other option is to use %s inside of the string like "This is a %s, %s with %s MPG" % "self.color, self.name, str(self.mpg)"
I hope this helps!


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