Not been able to get this to work


#1

Sorry to hijack this but I have not been able to get this to work even though I copied and pasted the code.
I get the message:
Oops, try again. my_car does not appear to be an instance of ElectricCar.

and the error :
Traceback (most recent call last):
File "python", line 24, in
TypeError: init() takes exactly 2 arguments (5 given)


Inheritance
#2

Exactly which lesson are you working on? My post above may be ahead of the lessons. Please post a link, and show us your code.


#3

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", "Toyota", "red", 70, )

this worked for me. but if i copy the model color and mpg once again then what's the point of inheritance :confused:


#4

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