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

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