我正在使用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