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 trialolusola ojo
Courses Plus Student 498 Pointscreating and using functions
Task : "Let's make sure we're always working with floats. Convert your arguments to floats before you add them together. You can do this with the float() function."
def add(num1.float(), num2.float()):
return (num1.float() + num2.float())
2 Answers
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsYou should not use methods/functions on arguments, they something like this instead:
def add(num1, num2):
num1 = float(num1)
num2 = float(num2)
return num1 + num2
Anibal Marquina
9,523 PointsWhen you define your function, you are calling the float() method on the num1 and num2 arguments which is incorrect. First, you need to pass the arguments and then call a method on them..float(num).
On the order hand, methods and functions are first class citizens, this means.. they can be pass as arguments, but this is not the subject of this challenge.
def add(num1, num2):
return float(num1) + float(num2)
print(add(3.4,5.5))
olusola ojo
Courses Plus Student 498 Pointsolusola ojo
Courses Plus Student 498 PointsThank you so much for reaching out with an answer Henrik