我正在使用Enthought Canopy编译器。我想用下面这段代码以获得来自用户的一个字输入:Python 3无法获得字母输入
starting_day = str(input("Enter the day you will be leaving: "))
然而
每当我通过运行指定的字母串的变量(它的运行后,我不断收到以下错误的程序测试VAR当我给它数)
Enter the day you will be leaving: monday
NameError Traceback (most recent call last)
C:\Users\user\AppData\Local\Enthought\Canopy32\App\appdata\canopy-1.1.0.1371.win-x86\lib\site-packages\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
174 else:
175 filename = fname
--> 176 exec compile(scripttext, filename, 'exec') in glob, loc
177 else:
178 def execfile(fname, *where):
c:\users\user\appdata\local\temp\tmpnwkfhu.py in <module>()
----> 1 starting_day = str(input("Enter the day you will be leaving: "))
2
3 lenght_of_stay = int(input("Enter the number of days you will say for: "))
4
5 print(starting_day, lenght_of_stay)
<string> in emulated_input(prompt)
<string> in <module>()
NameError: name 'monday' is not defined
如何将其更改为3 – user133745
您可能会发现[此问题](http://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid - 响应)在接受用户输入方面有用。 – jonrsharpe
@ user133745:请不要在评论中提问,请改为提问或[请教新问题](http://stackoverflow.com/questions/ask) – jfs