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 trialAndrew Smith
10,947 PointsQuiz: Try and Except, Q2 - How to convert Python function return to float
First part of question:
I need you to make a new function, add. add should take two arguments, add them together, and return the total.
Second part of the question (which I can't figure out)
Let's make sure we're always working with floats. Convert your arguments to floats before you add them together. You can do this with the float() function.
def add(one, two):
return(one + two)
3 Answers
Russell Sawyer
Front End Web Development Techdegree Student 15,705 PointsFor you to return the floated sum of the variables one and two you would need to write it like this.
return float(one+two)
or you could write it like this.
return float(one) + float(two)
Russell Sawyer
Front End Web Development Techdegree Student 15,705 PointsFloat is a function and is used like this
float(one)
Andrew Smith
10,947 PointsHow do I use Float() to convert the argument though? I tried this originally and it did not work.
def add(one, two):
float(return(one + two))
Yaqoob Al-Balushi
496 Pointsdef add(num1, num2): return float(num1) + float(num2) total = add(3,5)
Andrew Smith
10,947 PointsAndrew Smith
10,947 Pointsthanks, the second version worked, though the first one still returned incorrect