In Python 2, use raw_input()
instead of input()
to take string input from a user.
input()
tries to evaluate the input as a Python expression instead; a bare string is seen as a variable name in a Python expression, hence the NameError
. You could enter "pi"
instead, but that is not a great user-interface.
Demo:
>>> input("Please Enter Your Username: ")
Please Enter Your Username: pi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'pi' is not defined
>>> raw_input("Please Enter Your Username: ")
Please Enter Your Username: pi
'pi'