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 Python Basics (2015) Logic in Python Try and Except

"`add` returned the wrong results.": what is the meaning of this error?and how do i correct it through my coding?

please help me get through this!!!

trial.py
def add(salary , travel_money):
    float(salary + travel_money)
    return(salary + travel_money)

1 Answer

Thomas McDonnell
Thomas McDonnell
8,212 Points

Hi Priyanka Shukla, So lets start from task two where I think you are stuck. We want to add two arguments lets call them arg1 & arg2 and we need to make sure both numbers are floats BEFORE we add them. def add(arg1, arg2): return float(arg1) + float(arg2)

Now lets deal with catching our value error. We want to try and add the arguments, but return none if we get a value error

def add(arg1, arg2): try: return float(arg1) + float(arg2) except ValueError: return None

I hope this helps