Creating cla** methods


#1



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


It has the correct output but the lesson is not passing. It says:
Oops, try again. Make sure you pass the self keyword to the display_car() method.


I thought I would pass but apparently not.


class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self, Car):
        print "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(Car)


#2

here:

def display_car(self, Car):

no need to have a Car parameter


#3

When i do that it no longer prints and returns these errors:
Oops, try again. You can use str() to change mpg to a string as an easy way to add it to the display text.

Traceback (most recent call last):
File "python", line 11, in
TypeError: display_car() takes exactly 1 argument (2 given)


#4

this means you have to remove Car here:

print my_car.display_car(Car)

#5

Oh okay, it's working now. I guess it wasn't wrong the way I originally did it but the site wants me to do it the easier way. Thank you!

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 %s MPG." % (self.color, self.model, (str(self.mpg)))

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


#6

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