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 trialor porat
684 Pointstryin 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!
def add(pizza, icecream):
float(pizza, icecream)
return(pizza + icecream)
1 Answer
Alexander Davison
65,469 PointsYou'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:
def add(a, b):
return float(a) + float(b)
I hope you understand now :)
Good luck! ~Alex
or porat
684 Pointsor porat
684 Pointsthatx alex is was great!
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsNo problem ;)