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

Change the return statement to return the integer times 2. For example, Double(5) would return a 10.

Please help me with this

doubler.py
class Double():
    def __new__(*args,**kwargs):
        return int.__new__(*args,**kwargs)

2 Answers

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi, Thomas!

In step one, your new class should take 'int' as a parent. You're missing 'int' in your code above.

class Double(int):
    pass

In step 2, it's asking you to pass in self and one other argument, let's call it num. Then you need to use int to convert it and return that value:

class Double(int):
    def __new__(self, num):
        return int(num)

Then in step 3, you need to modify the return so it now returns the newly converted int times 2:

class Double(int):
    def __new__(self, num):
        return int(num) * 2

The goal here is to use int() as a function call. Right now, you are calling int's __new__ method and passing in values.

Thank you. This makes much more sense than the other ones i looked at. I actually understand whats going on here.