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

trouble with functions returning the wrong result

I'm supposed to create a function which takes 2 args. adds them together and returns a result, after converting the args to floats...something isnt working when i try to convert to floats

trial.py
def add(a, b):
    float(a)
    return a+b

1 Answer

def add(a, b):
    # creates a float from a but assigns it to nothing
    float(a)
    # the initial values of a and b added together, not turned to float
    return a+b

What you need to do is return float(a) + float(b), or a_new = float(a) b_new = float(b) return a_new + b_new