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

Mohamad Ismail
PLUS
Mohamad Ismail
Courses Plus Student 428 Points

Stuck 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)```

trial.py
def add(arg1,arg2):
    try:
        adding = arg1 + arg2

    except ValueError:
        return None

    else:
        adding = float(arg1) + float(arg2)
        return adding
Bleza Takouda
Bleza Takouda
5,129 Points

It think you missed a point. From the challenge description the else block is supposed to return the result adding . It should work if you move/replace the addition line with float casting to the try block.

Enzie Riddle
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Enzie Riddle
Front End Web Development Techdegree Graduate 19,278 Points

On 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!