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 trialRehan Hussain
Courses Plus Student 2,199 PointsConfused with the float!
This is not running for me!
def add(num1, num2):
float(num1,num2)
return(num1 + num2)
add(5,6)
5 Answers
Stuart McIntosh
Python Web Development Techdegree Graduate 22,874 PointsLine 2 is your issue you cannot put 2 arguments to float() - just one at a time
Rehan Hussain
Courses Plus Student 2,199 PointsWhat would be the correct way of writing this
float(num1) float(num2)
?
Stuart McIntosh
Python Web Development Techdegree Graduate 22,874 Pointshi there, you could do the following
def add(num1, num2):
float(num1)
float(num2)
return(num1 + num2)
add(5,6)
or to use less lines
def add(num1, num2):
return(float(num1) + float(num2))
add(5,6)
Rehan Hussain
Courses Plus Student 2,199 PointsHey guys,
Task 3 just won't run looking for some help!
def add(x,y):
try:
a = float(x)
b = float(y)
except ValueError
return None
else
return(a+b)
Stuart McIntosh
Python Web Development Techdegree Graduate 22,874 PointsHave you missed a colon after ValueError?