Creating Class Methods


#1

Here is my work

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)

print my_car.display_car()

Indentations are all there (i just didnt show them here). But the problem is that when submit the code I get an error message saying
Oops, try again. It looks like you didn't print "This is a silver DeLorean with 88 MPG.
even though it printed. I erased all of my codes and retyped it but i still get the same error message. Any ideas as to why this is happening? I appreciate the help. Thank you guys!


#2

remove str() from your return and enter a new line between your return and def display_car: str(self.mpg)


#3

like this?
display_car(self):
str(self.mpg)
return "This is a %s %s with %s MPG" % (self.color, self.model, self.mpg)


#4

Its still not working. I have no idea what is wrong.


#5

Never mind! I figured it out and it was probably the stupidest mistake. I forgot to put a period after MPG. I appreciate the help though.


#6

Had exactly the same issue, thanks for sharing ! :joy:


#7

I am facing same problem. Thanks for sharing.


#8

me too :smile: i forgot about how strict it is