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

not understanding what I am doing wrong in the code

Bummer! add did not return the correct result.

not really getting what is wrong as its working in workspace.

thanks Sri

trial.py
def add(num1,num2):
    try:
         total = float(num1) + float(num2)
    except ValueError:
         return()
    else:
        return(total)

4 Answers

Gabbie Metheny
Gabbie Metheny
33,778 Points

Everything looks great, just two slight tweaks are needed to your return statements. You don't need the () for a return, and Kenneth wants you to explictly return None in the except block, using keyword None. Then it should pass!

Hey thanks much , just got it .

Thank you Sri

Hi all, I got it fix it , its only successful when I give return None and not return()

Thanks Sri

Keith Whatling
Keith Whatling
17,752 Points

You are on the right track, two minor issues here.

Firstly, you have parenthesis on your return statements, this I think would return a tuple.

Secondly; the value error is returning a blank tuple, not None. None is a reserved word in python for being explicit about nothing.

def add(num1,num2):
    try:
         total = float(num1) + float(num2)
    except ValueError:
         return None
    else:
        return total
Manish Giri
Manish Giri
16,266 Points

For the except block, you should return None.