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 trialBo Chen
Courses Plus Student 848 PointsI'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
def add(num1, num2):
try:
return(float(num1) + float(num2))
except ValueError
return(None)
2 Answers
juliansteffen
9,802 PointsDear 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
juliansteffen
9,802 PointsDear 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
Bo Chen
Courses Plus Student 848 PointsBo Chen
Courses Plus Student 848 PointsWell 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.