7. Creating Class Methods


#1


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

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


#2

Only if the string interpolation represents it as a string.

%s  => str(self.mpg)

%d  => self.mpg

#3

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