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 trialDidier Borel
2,837 Pointsconverting 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?
var1=float(var1)
var2=float(var2)
def add(var1,var2):
return (var1+var2)
1 Answer
Haider Ali
Python Development Techdegree Graduate 24,728 PointsHi 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 :)
Thanks,
Haider