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

Abigail Solomon
seal-mask
.a{fill-rule:evenodd;}techdegree
Abigail Solomon
Data Analysis Techdegree Student 4,203 Points

Why can't I call my function?

So I assigned "Hello " + name to the variable hello within the hello_student function, but I cannot call this function at all. Whenever I call it using hello_student(Gabriel), it gives me a NameError and says that name is not defined, even though I put in a name as a literal argument for the function. When I run the code below, it gives me back an assertion error and claims I don't have a hello variable at all. I do have one but a local one for the hello_student function like the instructions wants, not a global one.

What am I doing wrong?

creating_functions.py
def hello_student(name): 
    hello = "Hello " + name
    return hello

print(hello_student("Gabriel"))

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hi Abigail Solomon 👋

Looks like you're currently trying to print the value but the challenge is asking you to store the returned value in a variable called hello. Since the hello you created is only scoped inside the function the test can't access the value and causes the error saying it's not defined.

To fix this you'll want to create a new hello variable after your function definition, in the global scope and call the hello_student function like so:

hello = hello_student("Gabriel")

Hope this clears things up! 🙂