Inheritance


#1



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



None


how do i print everything: model color mpg n battery type?


Replace this line with your code. 
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"
        return self.condition
class ElectricCar(Car):
    def __init__(self, model, color, mpg, battery_type):
        super(ElectricCar,self).__init__(model, color, mpg)
        self.battery_type=battery_type
        
    
my_car = ElectricCar("DeLorean", "silver", 88,"molten salt")
print my_car


#2

Hi @yang96,

You can override the display_car method by writing a new version of it for the ElectricCar class. Within that method, add the information about self.battery_type to the statement that produces the output. Try it out, and post it if you would like us to look at it.


#3

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