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

Mujahid Chowdhury
Mujahid Chowdhury
5,108 Points

This is a hard one

I have tested this on the console and it works but I keep getting ht eerror "Bummer! Try again!" :(

Any help?

trial.py
def add(num1, num2):
    return (float(num1) + float(num2))
try:
    num1 = int(input("Give me a number: "))
    num2 = int(input("Give me another number: "))
except ValueError:
    return ("None") 
else:
    add2 = add(num1, num2)
    print(add2)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I see that you've worked on this a lot! You are sooooooo close. And it's not so much that your code is wrong, it's just that it's not doing what Treehouse wants. And the biggest thing here is that Treehouse is going to send in numbers to your code to test it. And you are promptly writing over what they're sending with your input prompts to the user. Also, in the exception you're returning the string "None" not the value None.

Take a look at just how close you really are:

def add(x,y):
    try:
        return float(x) + float(y)
    except ValueError:
        return None

Hope this helps! :dizzy:

Mujahid Chowdhury
Mujahid Chowdhury
5,108 Points

Wohoo it worked! I think I understand how this thing works now. I cant add in any input prompts. Also I cant use none as a string.

Thanks Jennifer! :)