Jake Williams2,434 Points
Multiplying the doubler.py challenge
I know this is way off but I'm not sure how to get this to multiply.
class Double(int): def __new__(cls, *args, **kwargs): self = super().__new__(cls, *args, **kwargs) def __mul__(self, other): if int = 5 if other = (int) *2 return (int)* other
Chris FreemanTreehouse Moderator 65,283 Points
Hey Jake Williams, you’ve created a really cool teaching moment!
In the early tasks, the
__new__ method is missing a
return statement. Something like
return self works.
Now the cool part! For Task 3, you really only need to add “* 2” to the
This works because the
self * 2 calls the
__mul__ method inherited from
int. However, since you created your own
__mul__ method, it overrides the inherited version. Therefore your local method has to work to pass Task 3.
def __mul__(self, other): return int(self) * other
would get it done ✅. Or, simply delete the whole
Post back if you need more help. Good luck!!!