Inheritance>>WHAT IS WRONG WITH MY CODE?


#1

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 " + my_car.color + " " + my_car.model + " with " + str(my_car.mpg) + " MPG."
    def drive_car(self):
        self.condition = "used"
my_car = Car("DeLorean", "silver", 88)
print my_car.condition
my_car.drive_car()
print my_car.condition

class ElectricCar(Car):
    def __init__(self, model, color, mpg, battery_type):
        my_car.model = model
        my_car.color = color
        my_car.mpg = mpg
        my_car.battery_type = battery
my_car.battery_type("molten salt")
my_car.model("DeLorean")
my_car.color("Red")
my_car.mpg = 88

#2

We've already answered this question in your previous topic. Go back and read it carefully.

Also, please visit the topic on Formatting Code Samples in posts that is pinned at the top of the General Index.

https://discuss.codecademy.com/


#3

I don't get it. Can't you help me on here?


#4

Which thread do you wish to keep? Is this a new question? If so then the problem is that the earlier issue is still not resolved in the above code. It's confusing me.


#5

We need to create an instance and pass the properties in the argument.

my_car = ElectricCar("DeLorean", "Red", 88, "molten salt")

The lines above (in the quote) should be removed from the code.

This needs to be fixed...
`

self.color

and same with the other two.


#6

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