Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Logic in Python Try and Except

Bo Chen
PLUS
Bo Chen
Courses Plus Student 848 Points

I'm not sure what to put for the else

The instructions say to add an else but I'm not sure what to put in the else

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

2 Answers

Dear Bo,

that's pretty good, just a little Syntax mistake you need to finish the line with :

except ValueError:
     return("And here something that explain the Error: Like \"num1\" or \"num2\" coulnd't cast to float")

Greetings Julian

Bo Chen
Bo Chen
Courses Plus Student 848 Points

Well actually, I'm supposed to add an else statement after the except block but I can't figure out what I'm supposed to put in the else block.

Dear Bo,

actually for this "task" you don't need a else Block. In words you try to cast and add the two numbers and might an error will happen you return a information or do something eles inside of

except ValueError:

Like i wanna do something a+b but if an error happen "catch" this error and do something else mostly by this course just return a errormessage.

Greetings Julian