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!

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

creating 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
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

You 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

Thank you so much for reaching out with an answer Henrik

Anibal Marquina
Anibal Marquina
9,523 Points

When 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)