Plz help me with my code (7/11 creating class methods)


#1




The first part of my code works and it is able to print condition, color, model and mpg without issue however when I try to make use of display_car I get the following error message.

Traceback (most recent call last):
File "python", line 15, in
AttributeError: 'Car' object has no attribute 'display_car'


My code should print "This is a silver DeLorean with 88 MPG." Thank you for your time and assistance.


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.condition
print my_car.model
print my_car.color
print my_car.mpg
print my_car.display_car


#2

display_car is a method.

print my_car.display_car()

#3

Your code has an additional issue that needs to be addressed.

This line is missing the string interpolation operator, which is %, and must be placed between the format string and the tuple that contains the values ...

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

#4

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