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 trialMohamad Ismail
Courses Plus Student 428 PointsStuck on Python Exceptions... help please!
Want to add an ValueError exception to the function add. I believe I have the correct format, yet I keep getting a can't convert an int error.
```def add(arg1,arg2): try: adding = arg1 + arg2 except ValueError: return None else: adding = float(arg1) + float(arg2) return adding
add(2,3)```
def add(arg1,arg2):
try:
adding = arg1 + arg2
except ValueError:
return None
else:
adding = float(arg1) + float(arg2)
return adding
Enzie Riddle
Front End Web Development Techdegree Graduate 19,278 PointsOn the second part of the challenge, it has you convert your arguments to floats before adding them. It seems in your try
block you have removed the floats. Your ValueError
block is fine. All you are required to do in the else
block is return your adding
variable. Hope this helps! Reply if you have any more questions!
Mohamad Ismail
Courses Plus Student 428 PointsThank you Bleza Takouda and Enzie Riddle ... I can see clearly now! Much appreciated.
Bleza Takouda
5,129 PointsBleza Takouda
5,129 PointsIt think you missed a point. From the challenge description the
else
block is supposed to return the resultadding
. It should work if you move/replace the addition line with float casting to thetry
block.