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
Arnav Goyal1,634 Points
Help in coding practice in python basics course.
I need help in challenge task 2 of 3 in the coding test.
def add(num1, num2): return (num1+num2) add(3, 4)
Jennifer NordellTreehouse Teacher
You can view one of my previous explanations for the solution to this challenge here: https://teamtreehouse.com/community/hi-learning-about-python-in-python-basics-stuck-on-this-lesson
Hope it helps!
Alexander Davison65,468 Points
So this code works for the first task, but on task 2, you have to transform the a and b to float. Here is a better example:
def add(a, b): return (a + b)
Also, don't call the function, just write the function out. The Code Challenge will test the function for you.
For task 3, it is asking for some error handling. because if the value (in this case, a and b) transforming into a float might return an error, and that isn' t user-friendly. So you want to "catch" the error and just return None. Here is the full code:
def add(a, b): try: return float(a) + float(b) except ValueError: return None
Hope it helps! ~xela888