Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJake Williams
2,900 PointsMultiplying 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
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsHey 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 __new__
return
statement.
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 __mul__
method.
Post back if you need more help. Good luck!!!