Why does an error pop up here: var1 = "Trey" var2 = "Tanner" var3 = "Ellis" var4 = "Jake" var5 = "Christine" question = input('What is your name? ') if question == "var1": print('Welcome Back Trey') Error: Traceback (most recent call last): File "Hi.py", line 6, in <module> question = input('What is your name? ') File "<string>", line 1, in <module> NameError: name 'Trey' is not defined | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does an error pop up here: var1 = "Trey" var2 = "Tanner" var3 = "Ellis" var4 = "Jake" var5 = "Christine" question = input('What is your name? ') if question == "var1": print('Welcome Back Trey') Error: Traceback (most recent call last): File "Hi.py", line 6, in <module> question = input('What is your name? ') File "<string>", line 1, in <module> NameError: name 'Trey' is not defined

19th May 2017, 9:48 PM
Tanner
10 Answers
+ 16
You may have a look at this discussion, may be this issue is related to version of Python: http://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined
19th May 2017, 11:32 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 13
Don't use double quote with var1 while checking the condition, because it's a variable name. Use either var1 or "Trey" https://code.sololearn.com/ceFGuvfhkqfu/?ref=app
19th May 2017, 9:59 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 2
I think the error is not in the code you showed us. Even with the quotes it should not give the error.
19th May 2017, 10:14 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 2
But that's not what's causing the error @Mark
22nd May 2017, 10:59 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
remove quote marks from var1 since a variable
19th May 2017, 10:01 PM
Recho
+ 1
Have u tried using raw_input() rather than input() There are difference in python 2 and python 3 input in python 2 runs as an expression. var1 = "annie" var2 = "hannah" var3 = "amy" if raw_input("Enter your name: ").lower() == var1: print ("annie is here") else: print ("Invalid access") It works if uses raw
21st May 2017, 2:04 AM
Dave Lee
Dave Lee - avatar
+ 1
Why dont you just do: Choice = input('what is your name?').strip() while Choice not in 'trey': print('We do not recognize your name') if choice == 'trey': Print('do something') (Not indented properly fix it yourself)
22nd May 2017, 2:02 PM
Sean Cedano
Sean Cedano - avatar
0
Hey i tried doing what you suggested and this error came up: What is your name? Trey Traceback (most recent call last): File "Hi.py", line 6, in <module> question = input('What is your name? ') File "<string>", line 1, in <module> NameError: name 'Trey' is not defined Code- var1 = "Trey" var2 = "Tanner" var3 = "Ellis" var4 = "Jake" var5 = "Christine" question = input('What is your name? ') if question == var1: print('Welcome Back Trey')
19th May 2017, 10:08 PM
Tanner
0
Don't put variable names as strings in a statement, so instead of "var1" put in var1 instead.
22nd May 2017, 10:57 PM
Mark
Mark - avatar
0
You forgot your ; at the end of print();
24th May 2017, 12:11 AM
Tina Gibson
Tina Gibson - avatar