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 Try and Except

Matthew Williams
Matthew Williams
3,103 Points

I'm trying to add two functions together but that doesn't seem to be working.

I'm trying to do as they say. I made my add() function and even put in variables within.

add(one, two): one = int(1) two = int(2)

I'm sure that's how it's done but I'm not getting anything returned to me.

trial.py
add(one, two):
    one = int(1)
    two = int(2)
Dinesh kumar
Dinesh kumar
2,777 Points

In this challenge you have to return the value by adding. Try doing this,

def add(a,b): return (a+b)

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Matthew! Dinesh is correct. You must add the two numbers coming into the function and then return the sum of the two numbers. Currently, your code contains neither a return statement nor anything that would add the two arguments.

My code will look much like Dinesh's but I will use the parameter names you've chosen. Take a look:

def add(one, two):
    return one + two

Here we define a function named "add". This function has two parameters named "one" and "two". You may think of parameters as variable declarations that accept a value from another piece of code. These variables are scoped to the function and will cease to exist when the function is done executing. The function returns the sum of whatever one and two are equal to. So if I did this:

print(add(7, 9))

The call to the function would send in the 7 and 9 to the add function. The one parameter would be assigned the value of 7 and the two parameter would be assigned the value of 9. We would then add the 7 and 9 together and return the result to the piece of code that called it. And because this is inside a print statement, 16 would be printed out. Hope this helps clarify things! :sparkles: