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

Maryan Tuzyak
Maryan Tuzyak
1,495 Points

converting the arguments into floats

i have tried converting the top arguments into floats but not sure if doing it properly i'm assuming converting arguments to floats before adding them ,tried float() to total and add keeps telling me error in line 1

trial.py
def add float((n1,n2)):
    return(n1+n2)
total = add(2,8)
print(total)

1 Answer

Kent ร…svang
Kent ร…svang
18,823 Points

You can't convert the argument-list - instead you should consider to convert the numbers inside your function. This is how I would do it:

def add(a, b):
    return float(a+b)

# but you could also do something like this for clarity: 
def add(a, b):
    a = float(a)
    b = float(b)
    sum = a + b
    return sum

Hope this helped.