7. Creating class methods


#1

Hi, What's wrong with my code pls: It says Oops, try again. Make sure your Car class has a display_car() method.

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

#2

Take a closer look at your indentation, especially where the display_car() method is defined.


#3

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()

you should add the "." in the return statement and you should have a print before you call the display_car()