Calling drive_car does not work, removing it does? Bad directions?


#1



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


The directions instruct us to call the drive_car() function/method. However, the code only works once 'drive_car(my_car)' or 'drive_car()' is deleted (I've tried both). I get the following error message:

Traceback (most recent call last):
File "python", line 15, in
NameError: name 'drive_car' is not defined


Clearly drive_car is defined on line 9.... But I am obviously missing something. Can you help?


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

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


#2

@ingame4th ,

You have this line ...

drive_car()

Which Car do you want to drive, and how do you indicate that?


#3

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