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 trialKyle Hille
720 PointsTrial.py float num1 + num2
To start, I don't want someone just to give me the answer.
I guess I'm kinda confused about how to use float correctly here. I've tried putting float in add, for both and each num I've attempted to put it in return, which gives an error I've tried to add float for both individual number in add(15, 2) and each individual.
Did we learn how to use float()? Did I sleep thorough this class? lol
def add(num1, um2):
return(num1 + num2)
add(15, 2)
1 Answer
Shreyas Papinwar
2,371 PointsSyntax error dude - Its easy -
def add(num1, num2):
return float(num1) + float(num2)
Kyle Hille
720 PointsKyle Hille
720 PointsWhile I did say that I didn't want to just be given the answer, i'll take it, but with another question.
I tried this method and it didn't work for me before because I had return and float, for each, parenthesis still up. so like...
return (float(num1) + float(num2))
When should I or should I not continue to use parenthesis when it's needed at first? when I'm giving a different value, such as float to the 'X'?
Shreyas Papinwar
2,371 PointsShreyas Papinwar
2,371 PointsHey parenthesis are really not need in python 3 just use -
return float(num1) + float(num2)
you can also do -
sorry for the direct answer but its to straight forward, so I think it seemed fine.
BUT NOTE - if you think that parenthesis makes your code easy to read you can use them, its your choice.