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 trialsonam rathore
703 Pointswhat is the solution to task 2 of 3 functions
what is the solution to this question?
def add(float(num1),float(num2)):
return(num1+num2)
add(2,3)
3 Answers
jacinator
11,936 PointsYou've got the right idea, you're just trying to do it in the wrong place. Try it like so instead.
def add(arg1, arg2):
return float(arg1) + float(arg2)
Seth Kroger
56,413 PointsIn Python you don't need to do anything type-wise when defining the function arguments. float()
could be interpreted as code to run as part of the function but that shouldn't start until the next line. I say leave it off but add it below if you need to convert to floats.
jacinator
11,936 PointsDefining def func(float(arg))
returns a SyntaxError
. It is not valid Python.
sonam rathore
703 Pointsya.. thanks a lot.. the program is working now.