7/11 Passing Error?


#1

I have tried to look at other error checks on 7/11, but none of them have worked for me. My code is this:
class Car(object):
condition = "new"
def init(self, model, color, mpg):
self = self
self.model = model
self.color = color
self.mpg = mpg
def display_car(self, model, color, mpg):
self = self
self.model = model
self.color = color
self.mpg = mpg
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.condition
print my_car.model
print my_car.color
print my_car.mpg

print my_car.display_car(self, model, color, mpg)

I continue to get the error message "Oops, try again. Make sure you pass the self keyword to the display_car() method." Does ANYONE have a solution for my problem? I'm desperate!


#2

Use:

my_car.display_car(model, color, mpg)

Python takes care of the self argument.

If it didn't, then you would do:

Car.display_car(my_car, model, color, mpg)

Which also works, but is not what you should do.

self doesn't exist at all in the context where you used it.

Your display_car should not require any information other than self, because it should look up the information in self where that information is already stored.

The error message is poorly phrased, it should be saying:
"Oops, try again. Make sure your display_car method has a single parameter, self."


#4

What is wrong with my code?

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, self.mpg)
my_car = Car("DeLorean", "silver", 88)
print my_car.display_car()


#5

You forgot a period at the end of MPG. Codecademy is annoying about that.


#6

hello raelito. thank you for your repply, seems this is not the problem here, with or without the period the very same happens :frowning:


#7

You also need to convert the MPG to a string; use str(self.mpg). You will have to convert numbers to strings for use in these kinds of things, so try to remember to use the method when applicable.

class Car(object):
condition = "new"
def __init__(self, model, color, mpg):
    self.model = model
    self.color = color
    self.mpg   = mpg
def display_car(self):
    str(self.mpg)
    return "This is a %s %s with %s MPG." %(self.color, self.model, self.mpg)