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

Help me!!!! How to call a function and save the return value to a variable.

I had tried many times for Call the hello_student() function and save the return value to variable with [ hello = hello_student("name")] But I am still fixing bug "Bummer: NamError: name hello_student is not definied.

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

2 Answers

Steven Parker
Steven Parker
231,269 Points

It's not clear which task you are on, but here's some hints:

  • in task 1 the function should return a string value, you won't need to "print" anything
  • the function needs to return the literal value "Hello " combined with the name
  • literal strings must be enclosed in quotes
  • in task 2 you will call the function and assign a variable after the function (not inside it)

Task 1 is ok. But I stucked with Task 2. As I mentioned before, I had called the Hello_student(name) function and I defined the variable with name "Hello". And I assigned variable (Hello = hello_student(name)) with name is parameter. Can you see my code as below:

name = "Alice" def hello_student(name): hello = hello_student(name) print(hello)

But I have still received the Bummer Error: 'hello_student' is not defined. Can you show me the right code for this problem?

Steven Parker
Steven Parker
231,269 Points

To preserve the code's appearance, use Markdown formatting (:point_left: click on the highlighted words for a video showing how).

I looks like you haven't applied my hints to your code yet. I'll restate them knowing you're on task 2:

  • the function must return a string value, you won't need to use "print" at all
  • the function needs to return the literal value "Hello " combined with the name
  • literal strings must be enclosed in quotes
  • if you passed task 1, leave the function alone when you do task 2 (the current code won't pass task 1)
  • all the code for task 2 will be added after the function (not inside it!)

Try recreating your code using these hints. If it doesn't pass after that, post your revised code here but be sure to use the formatting.

Hi Asher Orr, As I mentioned before, I have tried many times to call the hello_student() function and save the return value to a variable called hello. (in Task 2). And I had write as below:

name = "Alice" def hello_student(name): hello = hello_student(name) print(hello)

But TeamTreeHouse console alarmed: NameError: name 'hello_student' is not defined. Can you explain for me with error? And can you show me the Right Code for this problem?