Classes_Creating class methods


#1

Error:
File "python", line 8
print This is a %, %, with, % MPG" (str(self.color),str(self.model),str(self.mpg))
^
SyntaxError: invalid syntax

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        print This is a %, %, with, % MPG" (str(self.color),str(self.model),str(self.mpg))

my_car = Car("DeLorean", "silver", 88)
print my_car.condition
print my_car.model
print my_car.color
print my_car.mpg
my_car.display_car()

#2

missing quotation mark (") at the beginning of the string


#3

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