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

or porat
or porat
684 Points

tryin the float() function

hey, its ask me to use the float() function, i did it but still cant pass this quizz. whats wrong with my cod? thanx!

trial.py
def add(pizza, icecream):
    float(pizza, icecream)
    return(pizza + icecream)

1 Answer

You're close!

The float() function doesn't change a variable in place, but it does returns a temporary value (that could be used and manipulated and stored).

Let's pretend we're in the Python Shell:

>>> a = 10
>>> float(a)
10.0
>>> a
10

As you see, it returns a value that is the float form of a, but it doesn't change a itself. a will still be the number 10.

So, in your code, you have to change the values to float and add them at the same time, like this:

trial.py
def add(a, b):
    return float(a) + float(b)

I hope you understand now :)

Good luck! ~Alex

or porat
or porat
684 Points

thatx alex is was great!

No problem ;)