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

stuck

Code gives an error on work space but works fine on my computer

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

2 Answers

Steven Parker
Steven Parker
231,269 Points

The challenge says to "Convert your arguments to floats before you add them together." The key word there is before.

If you write float(x+y) the addition will occur first, then the result will be handed over to float.

:point_right: You need to re-write it so each argument is convert to a float before they are added.

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

it still gives me an error