Classes_Inheritance


#1

error:
new
used
Traceback (most recent call last):
File "python", line 30, in
TypeError: init() takes exactly 4 arguments (5 given)

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,str(self.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):
self.model = model
self.color = color
self.mpg = mpg
self.battery_type=battery_type

my_car=Car("DeLorean","silver",88,"molten salt")


#2

here:

my_car=Car("DeLorean","silver",88,"molten salt")

You forgot to update your car to an electric car, its currently still a normal car


#3

So what needs to be done?


#4

you need to upgrade your car (my_car) to an electric car, its no longer a regular car


#5

okok got my mistake! thanks
I need to decalare my new object properly with the correct class addressing


#6