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 trialSabry Salman
2,465 Pointsusing floats
i am supposed to convert the two arguments into floats before adding them. i used this code in the shell and it works - but the answer seems to be wrong on the module. any help appreciated. thanks!
def add(var1, var2):
float(var1)
float(var2)
return (var1+ var2)
answer = add (5, 10)
print (answer)
1 Answer
Steven Parker
231,236 PointsBe careful when testing challenges in an external REPL. It's easy to get false positive results when using less rigorous testing than the challenge uses. In this case, I'd bet your tests did not include providing string arguments.
The "float" funciton doesn't change the value of it's argument, it just returns the converted value. So for it to be effective, it must be assigned. passed as an argument. or returned. For example:
float1 = float(var1)
Then of course you would use "float1" in later calculations
Also, the challenge only requires you to define the function, you don't need to call it yourself or to print anything.