9/11 help


#1

Hi, the program is showing me this error message : "Oops, try again. Make sure you've defined a new ElectricCar class after defining Car." but when I run my code in PyChar it runs without the problem. Do you know what is the problem?
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):
    print "This is a %s %s with %s MPG." % (self.color, self.model, self.mpg)

def drive_car(self):
    self.condition = "used"

class EletricCar(Car):
def init(self, battery_type):
self.battery_type = battery_type

my_car = EletricCar("molten salt")

print my_car.battery_type


#2

Double check your spelling with the ElectricCar class! Codecademy will often require spelling to be correct to determine if an answer is right.


#3

I ran into an issue with the 9/11 module as well. Below is the solution I found on stackoveflow. I would be interested how other people have solved this problem without competently overwriting the init method.

class ElectricCar(Car):
    def __init__(self, battery_type, *args, **kwargs):
        super(ElectricCar, self).__init__(*args, **kwargs)

Here is a refference to the solution: http://stackoverflow.com/questions/8333354/how-to-override-constructor-of-python-class-with-many-arguments


#5

This works

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, self.mpg)
        
    def drive_car(self):
        self.condition = "used"
        
class ElectricCar(Car):
    def __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", "Tesla", "dark green", 100)
print my_car.display_car()

#6

The subclass "ElectricCar" can have an improvement:

class ElectricCar(Car):
def init(self,battery_type,model, color, mpg):
self.battery_type = battery_type
return super(ElectricCar,self).init(model, color, mpg)