Creating class methods


#1



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


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


it does print "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):
        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()


#2

Hi try to change this line

return "This is a %s %s with %s MPG" % (self.color, self.model, str(self.mpg))

to

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

#3

Its literally just missing the period at the end of your sentence. Just add "." after "MPG"


#5

WOW! Lol thanks dude


#6

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