Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Advanced Objects Double

Jake Williams
Jake Williams
2,900 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

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,064 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!!!