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 trialClainos Machemedze
1,330 Pointsconverting arguments into float before addition operation
am trying to convert arguments into float before addition operation
def add(pardy,pray):
return(pardy + pray)
add.float((17,49))
2 Answers
Ashmit Pathak
4,441 Pointsdef add(agr1, arg2): ashmit = float(arg1) pathak = float(arg2) return ashmit + pathak this is the way you can solve this instead of the more complicated piece of code have written to solve this problem and yaa! the most important thing is it is bit more readable and you can pass the test with this
i hope this works!
Jon Mirow
9,864 PointsHi there!
Just a typo. At the moment you have
add.float(...
That will tell python that add has a method called float and to go and get that, but of course add is just a function so it doesn't work. The call should look more like this:
add(float(number1), float(number2))
Which would convert each number to a float then pass them to the add function. OR if you wanted to pass them both in as integers and then turn the resulting value into a float after it's been returned from the add function (this might seem the same now, but if you changed what happens inside the function later, it could lead to different output):
float(add(number1, number2))
Clainos Machemedze
1,330 PointsThanks for your effort really appreciate it