Creating class methods


#1

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

error:
Oops, try again. Make sure your Car class has a display_car() method.
wat is the prob?
`


#2

can anyone pls help???


#3

now its showing
File "python", line 12
my_car = Car("DeLorean", "silver", 88)
^
SyntaxError: invalid syntax


#4

Oops, try again. Did you accidentally delete my_car?
whats happening!!


#5

patience, its a forum, it takes a bit of time.

look at this code:

test = "hello world"
"%s"  % test

there is no , after "%s"

you do have a , after `MPG." which is invalid syntax


#6

i removed it.. now getng anthr error
Oops, try again. Did you accidentally delete my_car?


#7

can i see an updated version of your code?


#8

its done..i got it..tysm :slight_smile:


#9