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

I'm really trying here! I can't get this down!

I'm really trying here! I don't ever recall using the float function before or especially even learning about it during any part of this course and all I can do is look up what the function float even is and after reading about it and even typing something in, I still can't do it! I hate feeling like I'm not up to the task!

def add(num1, num2):

1 Answer

Cameron Nilon
Cameron Nilon
15,601 Points

Hey Sean,

Don't beat your self up about it, it will come to you. So what your trying to achieve is convert the type. So let's say you pass two numbers but they are in the form of a string type an example would be ~ add("1", "2") you will need to convert these two sting types into number types, in your case they are to be of float type. I think I can best explain this in code so here is an example to drive this home for you.

def add(num1, num2)
   return float(num1) + float(num2)

# some use examples
# add("1", "2") this will return 3.0
# add(5, 10) returns 15.0 

For some more info on this topic look into type casting. This is generally used accross all different programming languages.