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

Issue solving this exercise

Hi Guys, I'm trying to execute below one and it is giving me an error saying "'add' did not receive correct output". But when I try to execute it in workspace it is working fine. Tried a lot of ways before I seek your help. Please suggest.

def add(num1,num2): try: num1=float(num1) num2=float(num2)

except ValueError:
    return('None')

else:
    return(num1+num2)   

total=add(4.5,3.4) print(total)

trial.py
def add(num1,num2):
    try:
        num1=float(num1)
        num2=float(num2)

    except ValueError:
        return('None')

    else:
        return(num1+num2)   

total=add(4.5,3.4)
print(total)

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing great, but there's a slight misinterpretation of the challenge requirements. If either one of those conversions fail, it wants you to return None (the special built-in-constant). Instead, you are returning the string 'None'. You can find documentation on the built-in constants in Python here.

Also, return statements don't need parentheses, so if I adjust just one line, your code passes:

I changed this:

 return('None')

To this:

return None

Hope this helps! :sparkles: