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

Vishal Sharma
Vishal Sharma
413 Points

Why is my code not working with try:? [Solved]

Its telling me that I am not passing Task 1 with this code for Task 3. Why is this? I have used the try: before the code where I convert the numbers to floats and I have the rest of what the question asks for. Help please!

trial.py
def add(num1,num2):
try:
    float1 = float(num1)
    float2 = float(num2)
except ValueError:
    return None
else:
    return (float1 + float2)
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Glad you were able to figure it out. Please feel free to post again to the forum if you have new questions! Keep up the good work!

1 Answer

Vishal Sharma
Vishal Sharma
413 Points

Never mind, I solved the problem. It was just an indentation issue.