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 trial

Python Python Basics (2015) Logic in Python Try and Except

what is the solution to task 2 of 3 functions

what is the solution to this question?

trial.py
def add(float(num1),float(num2)):
    return(num1+num2)
add(2,3)

3 Answers

You'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
Seth Kroger
56,413 Points

In 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.

Defining def func(float(arg)) returns a SyntaxError. It is not valid Python.

ya.. thanks a lot.. the program is working now.