7. Creating Class Methods


#1



Replace this line with your code.


#2

?
Please tell, what is the issue?


#3

Apart from the fact that I cannot figure out how to post my question :)??


#4

I have 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 %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.display_car()

When I click on Save and Submit the console box shows the correct output but I get a mesage saying IIt looks like I have not printed eetc etc.


#5

Solved.

I find it hard to believe but the problem was that I did not have a full stop at the end of the string to be printed. Clearly the code was correct but the 'teacher' is VERY literal minded.


#6

That was good, because i haven't learned about classes yet (I'm also in the process of learning Python) :grinning::sweat_smile:


#7

I think that the underlying 'teaching' software seems to check what you
have typed into the editor on a character by character basis. So even
if the actual Python code is correct you get an error message if your
'poutput' text string differs in any way from what it asks you for -
even to the extent of a missing full stop.


#8

Hiya, I am trying to get "The new silver etc etc The exercise did not ask for"new". How does one include "new" using the memorable variable "condition"?


#9

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