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 trialDrew Rollins
694 Pointsstuck on this challenge
been trying different solutions for hours. Not sure what else to try at this point.
Drew Rollins
694 Pointsdef add (one ,two): float (one, two) return (one+two)
1 Answer
Ken Alger
Treehouse TeacherDrew;
Okay, so after Task 1 we should be able to have our function return the sum of two things passed in, right? Works great if we do add(3, 5)
, we get 8
. What happens though if we do add("3", "5")
, we would get 35. Technically correct, but if we are expecting mathematical addition to occur we need to convert our input into floats, for this example. We can do that with the float()
method. If we do a float("3")
we wind up with a value of 3.0
. We can add that mathematically.
For the challenge then, we need to convert both of the arguments we passed into our add
function into floats before (or during) the addition process and return the result.
Hope it helps.
Ken
Ken Alger
Treehouse TeacherTo save a step in your code you could do:
def add (one, two): #not great argument names
return one + two
Convert each argument separately as float()
only takes one argument.
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherDrew;
Welcome to Treehouse!
Can you post the code you are trying?
Thanks.
Ken