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 trialDV Shop
1,482 PointsHelp 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.
def hello_student(name):
hello = hello_student("Vien")
print(hello)
2 Answers
Steven Parker
231,269 PointsIt'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)
DV Shop
1,482 PointsHi 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?
Asher Orr
Python Development Techdegree Graduate 9,409 PointsDV Shop, can you post the code using Markdown formatting? ( click on the highlighted words for a video showing how).
DV Shop
1,482 PointsDV Shop
1,482 PointsTask 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
231,269 PointsSteven Parker
231,269 PointsTo preserve the code's appearance, use Markdown formatting ( 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:
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.