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 trialLeah Tibbets
Python Development Techdegree Student 199 PointsFile "<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))
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'hello' is not defined
[MOD: added ```python formatting - cf]
3 Answers
Jon Brantingham
7,860 PointsI 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.
kols
27,007 PointsI 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
jb30
44,807 PointsAssuming 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.