9. Inheritance


#1



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


I don't know where my code is wrong;


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"

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

class ElectricCar(Car):
    __init__(self, battery_type, model, color, mpg):
        self.battery_type = battery_type
        self.model = model
        self.color = color
        self.mpg = mpg
my_car = ElectricCar("molten salt", "plasma", "blue", "55")


#2

You might start by considering what it is doing differently from what you want. (wrong does not go very far in describing that, it just avoids doing so)


#3

You forgot the word "def" in line 16.


#4

Also, when you created the new ElectricCar instance, you made it's final attribute "55", a string. Supply instead an integer 55.


#5

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