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

basil dhillo
PLUS
basil dhillo
Courses Plus Student 240 Points

please help me to solve this problem ??

how can i solve this problem ??

trial.py
try:
    x = float(input("give me 1 nmber"))
    y = float(input("give me second number"))
    float(total) = x + y

except ValueError:
    return None

else:
    return total

3 Answers

Lukas Coffey
Lukas Coffey
20,382 Points

Is this for the "Try and Except" challenge in "Python Basics: Logic in Python"? If so, you only need to convert the arguments the function takes into floats. So:

def add(a, b):
    total = float(a) + float(b)

You would put the try: right before you turn the arguments into floats to make sure they are really numbers. Hope this helps!

Lukas Coffey
Lukas Coffey
20,382 Points

No problem! Mark my answer as best if it worked if you don't mind :)

basil dhillo
PLUS
basil dhillo
Courses Plus Student 240 Points

I already marked your answer as best.. and it is working as well