Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Types and Branching If, Else and Elif

File "<stdin>", line 1, in <module> NameError: name 'hello' is not defined

This is my code:

first_name = input("What is your first name? ")
print("Hello", first_name)
    if first_name == "Zayden":
        print(first_name, "is learning Python")
print("Have a great day {}!".format(first_name))

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'hello' is not defined

[MOD: added ```python formatting - cf]

3 Answers

I can replicate this by running $ python hello.py instead of $ python3 hello.py. So, for anyone running into the same error, try running this using python3 instead of a legacy version:

$ python3 hello.py

I had this problem, and it was a simple solution.

I was already running python (you'll see >>> in the Terminal when python is active), but when you run the command "python hello.py", it is asking to startup python again.

Type in exit() and press enter to exit python. Then type in the complete command "python hello.py". This was it can also find the file you are looking for and should work now.

Assuming that your code is indented properly, your code looks fine and runs properly.

Your posted code has the line print("Hello", first_name). If instead you typed the line print(hello, first_name), then you would be referencing the variable hello, which you have not defined, and that would give you a NameError.