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

James Joseph
James Joseph
4,885 Points

Python: Try block challenge

Hi there, I'm having some issues with this Try block challenge I've looked at some forum posts but their code is a bit different from mine, it seems accurate but I guess not. Any help would be appreciated.

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

1 Answer

James Joseph
James Joseph
4,885 Points

I've figured it out by looking at someone elses topic..Indents.... along with changing the structure of my code a bit.

def add(num1, num2):
    try:
        na = float(num1) + float(num2)
    except ValueError:
        return None
    else:
        return(na)