How to perform the below:
def to_distance(speed, time):
return speed * time
speed = 10.0
to_distance(speed, 5)
in the context of a class. That is, using a class with a base class of int
and having a to_distance
method. The below attempt:
class Speed(float):
def __init__(self, n):
super().__init__(n)
def to_distance(self, n):
return self * n
running:
s = Speed(11.0)
results in a TypeError
:
TypeError Traceback (most recent call last)
<ipython-input-18-4c35f2c0bca9> in <module>
----> 1 s = Speed(11.0)
<ipython-input-17-6baa46f60665> in __init__(self, n)
2
3 def __init__(self, n):
----> 4 super().__init__(n)
5
6 def to_distance(self, n):
TypeError: object.__init__() takes no arguments