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 trialbasil dhillo
Courses Plus Student 240 Pointsplease help me to solve this problem ??
how can i solve this problem ??
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
20,382 PointsIs 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!
basil dhillo
Courses Plus Student 240 Pointsthank you sir
Lukas Coffey
20,382 PointsNo problem! Mark my answer as best if it worked if you don't mind :)
basil dhillo
Courses Plus Student 240 PointsI already marked your answer as best.. and it is working as well