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 Functions, Packing, and Unpacking Getting Info In and Out of Functions Functions with Arguments and Returns

creating functions

no matter what i do i keep getting an error saying that name is not defined.

creating_functions.py
def hello_student(name):
    hello=hello_student("emily")
hello_student(name)

2 Answers

The last line hello_student(name) calls the function passing in a variable named name for the name parameter. Since there is no name variable defined you receive the error. Something like this would work:

name = "emily"

def hello_student(name):
    return 'Hello ' + name
hello_student(name)

but that is not what you are being asked to do. Note the variable name and the parameter name are not the same thing.

For task 1 you are to create the hello_student function with a name parameter and return 'Hello ' followed by the value of the name parameter. I have done that above.

For task 2 you are to call the hello_student() function and save the return value to a variable called hello. You had that in your code (although in the wrong place).

If you put the two together you have:

def hello_student(name):
    return 'Hello ' + name

hello=hello_student("emily")

It looks like you overwrote your function with task 2.

Outside of the function this is ok for task 2.

hello=hello_student("emily")

But you will need to restore your code from task 1.

i took out hello=hello_student("emily") and i still get an error saying name isnt defined