"new.. new " not "new ..used" :( whyyyy?


#1



https://www.codecademy.com/courses/python-intermediate-en-egNXj/1/2?curriculum_id=4f89dab3d788890003000096

in Unit 11 ----> Classes ---> 8.Modifying member variables


it returns "new" after drive_car() method


I expected it to return "used


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))
    def drive_car (self):
        return self.condition == "used"

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


#2

if you would set condition to used (single equal sign is assign/update variable) instead of comparing it (two equal signs)


#3

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))
    def drive_car (self):
        return self.condition = "used"

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

changed it and I got this on the console :confused:

 File "python", line 10
    return self.condition = "used"
                          ^
SyntaxError: invalid syntax

and this on my screen :confused:
Oops, try again. Did you accidentally delete my_car?


#4

this might be help to you

def drive_car(self):
condition = "used"
self.condition = condition


#5

don't use a return keyword, you update a variable, you don't have to return it


#6

thanks for your help but deleting return did the job ^_^


#7

deleting return did the job thank you :smiley:


#8