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

Didier Borel
Didier Borel
2,837 Points

floats

i understand that I am being asked to make sure that my var1 and var2 are floats, but i am not quite sure, where and how to define that? also subsidiary question, can u remind me what a float is pls? is it basically a number with something after the decimal point, like 2.45 right, ? like an integer, but with a number after the decimal point.?

trial.py
def add(var1,var2)
  return (var1+var2)

1 Answer

Kourosh Raeen
Kourosh Raeen
23,733 Points

Use the float() function and pass the arguments to it:

def add(var1, var2):
  return float(var1) + float(var2)