Modifying member variables gives an odd error


#1

I am using the following 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):
    return "This is a " + self.color + " " + self.model + " with " + str(self.mpg) + " MPG."
def drive_car(self):
    self.condition = "used"

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

I get the following output:

used
None

Which is correct, but I get the following error at the bottom:

Oops, try again. You don't need to display_car().

`


#2

@patski111,
As indentation is VERY important in Python,
could you please re-edit your Original Post
so we can see, if you used the indentation properly.....

Please re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= https://discuss.codecademy.com/t/how-do-i-format-code-in-my-posts/28351
[extra's]
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet


#3

Thanks for the reply. I don't know what happened, but I went out of codecademy, then came back in and it worked.


#4
print my_car.condition
my_car.drive_car()
print my_car.condition