I can't drive my car!


#1



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

Oops, try again. It looks like you didn't update the condition of my_car to 'like new'.


I used the same bit of code I used earlier on when I was just trying to change the normal car class, but for some reason (unbeknownst to me) it created a different effect and just printed "new" again.


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 " + self.color + " "+ self.model + " with " + str(self.mpg) + " MPG."
    def drive_car(self):
        self.condition = "used"
class ElectricCar(Car):
    condition = "new"
    def __init__(self, model, color, mpg, battery_type):
        self.model = model
        self.color = color
        self.mpg = mpg
        self.battery_type = battery_type
    def drive_car(self):
        condition = "like new"

my_car = ElectricCar("DeLorean", "silver", 88, "molten salt")
print my_car.condition
my_car.drive_car()
print my_car.condition


#2

here:

    def drive_car(self):
        condition = "like new"

this will create a variable with a local scope (only existing inside the drive_car method), it doesn't update the member variable

If you don't remember, maybe you can look for inspiration in the drive_car method of your Car class


#3

You need to use self here to access condition appropriately ...

        condition = "like new"

See the reply above by @stetim94.


#4

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