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.
I followed kenneth coding, but when I use the add method with NumString(2.2) + 2 I receive a Type Error: float() argument must be a string or a number, not 'NumString'. I don't understand where the mistake is. Here my code:
class NumString: def init(self, value): self.value = str(value)
def __str__(self): return self.value def __int__(self): return int(self.value) def __foat__(self): return float(self.value) def __add__(self, other): if '.' in self.value: return float(self) + other return int(self) + other
Anthony Albertorio22,169 Points
It looks like your init function is off. You don't seem to have init(). Instead you have init() without the dunders. Change that and your code should work.
Ignazio CaloCourses Plus Student 1,819 Points
with this code
NumString(2.2) you're passing a number and not a string as parameter.
NumString("2.2") should fix the problem