Oops, try again. The only place the actual values of my_car should appear is when it is created; always use member variables to access these values


#1



This is what outputs to the code screen:
This is a silver DeLorean with 88 MPG.
None

It should work, at least it's returning the correct answer...


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

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


#2

This is the error message that kicks up at the bottom of the screen:

Oops, try again.
The only place the actual values of my_car should appear is when it

is created; always use member variables to access these values.


#3

For lesson 7, try this format:

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

#4

Sweet that worked, thank you mtf


#5

Hi @mattheal and @mtf ,

@mattheal's original code passed with no problems when I submitted it. @mtf's line of code also works, of course. It's not clear to me why Codecademy did not accept the original version when @mattheal submitted it. The only difference is that it uses the %d format specifier instead of %s. Both are acceptable for incorporating int values into strings.

Here's yet another version of the return statement that works by using the string format method ...

return "This is a {:s} {:s} with {:d} MPG.".format(self.color, self.model, self.mpg)