7. Creating Class Methods



The code is printing the result perfectly fine.
Shouldn't it ask for the mpg to be converted to string, as mentioned in the problem description?

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 %s %s with %d MPG."%(self.color, self.model, self.mpg)
my_car = Car("DeLorean", "silver", 88)
print my_car.condition


Only if the string interpolation represents it as a string.

%s  => str(self.mpg)

%d  => self.mpg


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