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

Need Help With Code Challenge Getting Name is Not Defined Error

This question is in regards to a code challenge where you need to call the hello_student function and save it in a variable called hello. So I was able to create a variable called hello and have the hello_student function saved in it. According to the videos, you can enter a name as a parameter in the function and the function will run. Well the error keeps coming up that name is not defined when I submit my code. I tried to define name by entering name = input("What is your name? ") in the body of the function and that did not work. Not sure exactly how to fix this.

def hello_student(name):
    return ("Hello {}".format(name))


hello = hello_student(name)

1 Answer

If you want hello to have a string value provided by the hello_student function, you could try

hello = hello_student("Victor")

or

name = "Victor"
hello = hello_student(name)

If you have name without quotes, python will interpret that as a variable, and expect you to provide a value for it before you use it.