Creating class methods


#1

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()
my output is This is a silver DeLorean With 88 MPG.
it gives error as Oops, try again. It looks like you didn't print "This is a silver DeLorean with 88 MPG.".


#2

in the string, you wrote With with an uppercase w, i suspect the string printed is case sensitive validated, so change it to with


#3

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