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
10 Respostas
+ 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
+ 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
+ 2
I think the error is not in the code you showed us.
Even with the quotes it should not give the error.
+ 2
But that's not what's causing the error @Mark
+ 1
remove quote marks from var1 since a variable
+ 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
+ 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)
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')
0
Don't put variable names as strings in a statement, so instead of "var1" put in var1 instead.
0
You forgot your ; at the end of print();