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 trialSiyuan Welch
3,025 PointsAdd a try block before where you turn your arguments into floats. Then add an except to catch the possible ValueError.
Add a try block before where you turn your arguments into floats. Then add an except to catch the possible ValueError. Inside the except block, return None. If you're following the structure from the videos, add an else: for your final return of the added floats.
7 Answers
Deni Chan
Courses Plus Student 19,384 PointsHey Siyuan! I tried your code and it worked. Probably you have to indent smth. Could you write your code with synthax highlighting,please?
Siyuan Welch
3,025 PointsThank you so much Deni, Oh, I see. You are right. It's the indent missed, it passed right now. And actually, I have no idea how to write code with synthax highlightning in community. I would like figure it out.
Jotham Teo
4,460 PointsHey Siyuan! I was stuck too, till I realized that its an issue with the indentation and not your code. "Def ....." line has no indentation, the rest of your lines should have indentation & I believe you will get through!
Jeffery Austin
8,128 PointsYou almost got it you just need to capitalize None, and you don't need parentheses for return.
return float(num1)+float(num2)
Deni Chan
Courses Plus Student 19,384 PointsHello Siyuan! I think you should write None (from capital letter). python is case-sensitive. Good luck!
Deni Chan
Courses Plus Student 19,384 PointsAlways welcome! to highlight your syntax just put 3 backticks (```) and specify the language. Good luck!
Siyuan Welch
3,025 Pointsdef add(num1,num2): try: float(num1)+float(num2) except ValueError: return None else: return float(num1)+float(num2)
Siyuan Welch
3,025 PointsI corrected them but still can not pass. Please help me out!
Ilia Galperin
6,522 Pointsdef add(arg1,arg2): try: sum = float(arg1)+float(arg2) except: return None else: return sum
Siyuan Welch
3,025 PointsSiyuan Welch
3,025 Pointsdef add(num1,num2): try: float(num1)+float(num2) except ValueError: return none else: return (float(num1)+float(num2))