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

How to convert arguments into floats before adding using python

Hi! I'm having a tough time converting arguments to floats before adding using python . Here is my answer which is wrong. this is challenge 2 of 3 in the python basics category. def add(x,y): return(x + y) x = float(x) y = float(y) return float(x) + float(y)

trial.py
def add(x,y):
    return(x + y)
    x = float(1)
    y = float(1)
    return float(x) + float(y)

1 Answer

Hi there!

Just a reminder that a return statement exists the function, so code following it doesn't execute. As you have a return statement on the 1st line of your function, this is how your function is run by python:

def add(x,y):
    return(x + y)

The next two lines I assume are for debugging? But your last line, the return statement should be all that you need. So

def add(x, y):
    return float(x) + float(y)

Should work.

Hope it helps :)

Thank you soooo much Jon!!! I spent at least 3 hours on that question today??‍♂️. Sad... Your a life saver. Thank you for your time.