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 trialCoding Lab 6
2,170 Pointschanging string to float
the challenge: Let's make sure we're always working with floats. Convert your arguments to floats before you add them together. You can do this with the float() function. I got the first two lines right, but can't change num1 and num2 to floats.
tried function(num1,num2) ....with and without quotes...between the two lines of code that are ok....no luck...... tired and trustrated
def add(num1, num2):
return num1 + num2
3 Answers
Perry Adkins
8,413 Points"""python
def add(num1, num2):
try:
add = int(num1, num2)
except ValueError:
print("That's not a number")
else:
return float(num1) + float(num2)
"""
Vedang Patel
7,114 Pointsnice try it doesn't work
Perry Adkins
8,413 PointsHi Vedang.
The screen shot was missing the code that is above the screenshot.
I will do something even better. I am going to provide you the link to a workspace. https://w.trhou.se/dpxua8thzs
Once you open the workspace, choose the try.py on the left hand side.
Good Luck.