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 trial

Python Object-Oriented Python Advanced Objects Double

Multiplying the doubler.py challenge

I know this is way off but I'm not sure how to get this to multiply.

doubler.py
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
MOD
Chris Freeman
Treehouse Moderator 68,423 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 __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!!!