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 Math

Math chapter

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

3 Answers

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.

I see, you misspelled float in foat. You miss the l.

Ignazio Calo
PLUS
Ignazio Calo
Courses 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

I agree with you, but then I don't understand why kenneth get the result using the same code I am using and using the code: NumString(2.2) + 2