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 trial

Python Python Basics (2015) Logic in Python The Exception to the Rule

Mariya Shklyar
Mariya Shklyar
1,022 Points

Need help with quiz

What did I do worng in the second question of the quiz?

one = 1
two = 2
def add(one, two):
    float(1)
    float(2)
    return(one + two)
Yuan Gao
Yuan Gao
8,947 Points

Hi Mariya, when defining the function you used "one" and "two" to name your variables, so the result you want to get would be (one + two). Also it's helpful to print out the result using "print()" to check your result.

one = 1 
two = 2 
def add(one, two):  
    return(one + two)
print (add(one,two))

What you use to name your variable when defining the function doesn't have to match with your actual input variable's name. For example, this would also work:

one = 1 
two = 2 
def add(apple, orange):  
    return(apple + orange)
print (add(one,two))

2 Answers

Julian Gutierrez
Julian Gutierrez
19,201 Points

There is no need to declare the variables just include the float conversion in your return.

def add(num1, num2):
    return float(num1)+float(num2)

【code challenge 1/3】

def add(num1, num2): return(num1 + num2)

【code challenge 2/3】

def add(num1, num2): a = float(num1) b = float(num2) return(a + b)

【code challenge 3/3】

def add(num1, num2): try: a = float(num1) b = float(num2) except ValueError: return None else: return(a + b)