class car(object):
"""A simple attempt to represent a car."""
def __init__(self,make,model,year):
self.make=make
self.model=model
self.year=year
def get_descriptive_name(self):
"""getting full name of the car"""
longname=str(self.year)+" "+self.make+" "+self.model
return longname
class battery():
"""defining the new battery class"""
def __init__(self,battery_size=70):
self.battery_size=battery_size
def describe_battery(self):
"""Print a statement describing the battery size."""
print("This car has a " + str(self.battery_size) + "-kWh battery.")
def get_range(self):
if self.battery_size==70:
range=210
elif self.battery_size==90:
range=270
message = "This car can go approximately " + str(range)
message += " miles on a full charge."
print(message)
class ElectricCar(car):
def __init__(self,make,model,year):
super(object,ElectricCar).__init__(model,make,year)
self.battery=Battery
my_tesla=ElectricCar('tesla','benz','2016')
print my_tesla.get_descriptive_name
my_tesla.battery.describe_battery()
my_tesla.battery.get_range()
Above code throws
Traceback (most recent call last):
File "python", line 27, in <module>
File "python", line 25, in __init__
TypeError: super() takes at most 2 arguments (3 given)
Above code throws the error showing the above one which I have posted. As it is throwing the super()
argument error. How to solve this error. In which the 25th line is:
super(object,ElectricCar).__init__(model,make,year)
and 27th line is
my_tesla=ElectricCar('tesla','benz','2016')