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

Fatimah Ghazal
Fatimah Ghazal
1,848 Points

when i convert an argument into float do i have to type float in the final return also?

and i cant pass the challenge Bummer! Try again!

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

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Fatimah,

You have the correct logic, you just have a few minor syntax errors that won't let you pass.

1) You forgot a colon after your def main(num1, num2):

2) Your else: keyword is slightly off by one space. It needs to be aligned with try: and except:

3) You can remove the parentheses from your last return statement: return a + b, although it still will pass just fine with them left in as you have them.

Good luck.