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

Drew Rollins
Drew Rollins
694 Points

stuck on this challenge

been trying different solutions for hours. Not sure what else to try at this point.

Ken Alger
Ken Alger
Treehouse Teacher

Drew;

Welcome to Treehouse!

Can you post the code you are trying?

Thanks.
Ken

Drew Rollins
Drew Rollins
694 Points

def add (one ,two): float (one, two) return (one+two)

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Drew;

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
Ken Alger
Treehouse Teacher

To 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.