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!
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
Nikhil Alexander1,444 Points
task 2 is no longer passing after i wrote the third part of the task... please help me correct my error
after writing the third part of the task the second task is being expressed as invalid......... i am not able to find out the error pertaining to the third task... will be grateful for any help or advice given...
def add(num1,num2): return(num1 + num2) add(1,1) def add(num1,num2): return(float(num1) + float(num2)) add(1,1) def add(num1,num2): try: int(float(num1) + float(num2)) except ValueError: return(None) else: return(num1 + num2) add(1,1)
Hey Nikhil! Couple of things here. You shouldent make multiple add functions, you should modify the already existing one at each step.
Also, the backend will send numbers to the function, so you dont need to do it yourself.
Lastly, using the float() function, returns a float from what you pass into it, but it dosent actually change the value.
test = 5 float(5) # This would return 5.0 print(test) # Test would still just be 5 tho. # So you need to do: test = float(test) # Now test would be 5.0
A little hint would be to just return the result of your expression in the try:
return float(num1) + float(num2)
And then just remove that else statement. Hope this helps!