7. Creating class methods



I can't really see the problem here. it seems right to me.
%s converts the int to a str right?

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, self.mpg)

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


Your code.. (have a typo)

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

can you tell difference between them ?

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


wow. perhaps the software is a bit too sensitive sometimes :sweat_smile:
Thank you


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