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

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.