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 trialThomas Ma
15,199 PointsChange the return statement to return the integer times 2. For example, Double(5) would return a 10.
Please help me with this
class Double():
def __new__(*args,**kwargs):
return int.__new__(*args,**kwargs)
2 Answers
Megan Amendola
Treehouse TeacherHi, 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.
Brian Kiefer
12,693 PointsThank you. This makes much more sense than the other ones i looked at. I actually understand whats going on here.