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

how to solve this,please answer

please help

trial.py
def add(a,b):
    try:
            a=float(a)
            b=float(b)
            return a+b
            except ValueError 
            return none

2 Answers

You super close! But you seem to have some indentation errors. Remember that everytime we write a ":" we want to indent 4 blocks for the next instruction. You have done way to many indents after your try:. Secondly you need to have a ":" after you except ValueError. And it needs to be on the same line as try:.. It may be simpler just to see the code:

def add(a,b):
    try:
        a=float(a)
        b=float(b)
        return a+b
    except ValueError:
        return None

thank you so much

I was having trouble with this question too. Have seen other answers, but this is the first one that worked.