Overriding methods, prints mixed_up gibberish


#1



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


This is what it prints, misplacing "Delahaye" instead of "100":
PS: I did "talk to the duck" prior posting... :slight_smile:

This is a 100 red molten battery with Delahaye MPG.
None
new
like new
None

MY CODE LOOKS LIKE:

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg = mpg
        
    def drive_car(self):
        self.condition = "used"

class ElectricCar(Car):
    def __init__(self, model, color, mpg,battery_type):
        super(ElectricCar,self).__init__(model, color, mpg)
        self.battery_type = battery_type
    
    def drive_car(self):
        self.condition = "like new"
      
    def display_car(self):
        print  "This is a %s %s %s with %s MPG." % (self.battery_type,self.color, self.model, str(self.mpg))
    
my_car = ElectricCar( "molten salt","Delahaye", "red", 100)

print my_car.display_car()
print my_car.condition
my_car.drive_car()
print my_car.condition


#2

Hi, @anaestereo,

The duck has advised me to have you to compare the order of the parameters in this method header ...

    def __init__(self, model, color, mpg,battery_type):

... to the order of the arguments in this instantiation statement ...

my_car = ElectricCar( "molten salt","Delahaye", "red", 100)

The order of the arguments in your instantiation statement should correspond to the order of the parameters in the __init__ method header. For example, the model should be the first argument, and color second.


#3

I knew that duck was nothing but trouble!!!! :slight_smile:

thanks a ton, appylpye.....I got my eyes set on the top method header for the Car class rather than the ElectricCar from which inherits....I really appreciate your time!!!


#4