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

seong lee
seong lee
4,503 Points

Help me with this please

on python basics I am getting confused on the third task for try and except function exercises

trial.py
def add(one, two):
try:
    num3 = float (one) + float (two)
except ValueError: 
        return None
else:
    return num3

5 Answers

Steven Parker
Steven Parker
231,269 Points

Be careful with indentation.

Remember that to be considered part of a function, each line must be indented more than the def Β line.

Otherwise, your code looks good, so once you fix the indentation you should pass.

Steven Parker
Steven Parker
231,269 Points

Using your code and changing only the indentation, I got this to pass:

def add(one, two):
    try:
        num3 = float (one) + float (two)
    except ValueError: 
        return None
    else:
        return num3
seong lee
seong lee
4,503 Points

It still does not work actually Can you help me please

Steven Parker
Steven Parker
231,269 Points

Really? See the example I added to my answer. Did you do something else?

seong lee
seong lee
4,503 Points

oh i'm very sorry I accidentally put a semicolon between except and ValueError

seong lee
seong lee
4,503 Points

and thank you, i was able to pass