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

John Paul Masters
John Paul Masters
1,722 Points

Task 3 Help

I don't understand the last bit with the return and added floats, I don't know what to do

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

You have almost everything!

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

You are just missing the return num1 and num2 on your else return on the end! but you got this!

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey John Paul,

You code is actually completely correct except for the indentations. Python is very "indent dependent," and if your off by one space, the code will break.

In this case, you didn't indent your try block of code, so right now, it is outside of the method, instead of inside. Just fix up the indentation and the rest is good:

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

Keep Coding! :) :dizzy: