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

Didier Borel
Didier Borel
2,837 Points

converting to floats

i am not quite sure what I am doing wrong here. basically they want me to make sure my arguments are floats. remind me, just to be sure, a float is an integer but with a value after the decimal, like 2.45, correct?

def add(var1,var2):
  return (var1+var2)

1 Answer

Haider Ali
.a{fill-rule:evenodd;}techdegree seal-36
Haider Ali
Python Development Techdegree Graduate 24,728 Points

Hi Didier, you are correct in saying floats are (basically) numbers with a decimal point. The reason your code is not working is because you should have converted the arguments to floats inside the function because outside of the function, they do not exist. This is due to function scope.

def add(var1,var2):
  return float(var1) + float(var2)

If you have any further questions, please leave a comment :)