Reputation: 45
I'm new to python and have problems with input.
When I'm using command userName = input('What is your name? ')
it says something like this:
>>> userName = input('What is your name? ')
What is your name? Name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'Name' is not defined
What I must do with it?
Upvotes: 1
Views: 1324
Reputation: 96
change it to :
userName = raw_input('What is your name?')
In Python 2.x:
raw_input()
returns string values and
input()
attempts to evaluate the input as command
But in python 3.x, input has been scrapped and the function previously known as raw_input is now input.
Upvotes: 2
Reputation: 2534
The function input()
evaluates input as a command--that is why numbers work, but not generic strings that cannot be executed. To achieve attaching a string to a variable, use the more universal raw_input()
, which reads everything as a string.
Your new code will now look like
userName = raw_input('What is your name? ')
Best of luck, and happy coding!
Upvotes: 1