【发布时间】:2014-05-05 13:55:47
【问题描述】:
我正在使用 Enthought Canopy 编译器。我正在尝试使用以下代码从用户那里获取单词输入:
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
-
您可能会发现this question 在接受用户输入方面很有用。
-
@user133745:不要在评论中提问,edit你的问题,或者ask a new one
-
@J.F.Sebastian:不是那个问题;寻求建议是题外话,并且将您的问题更改为新问题也是不受欢迎的。编辑问题是为了澄清当前问题,而不是添加新问题。
-
@MartijnPieters:“如何将其更改为 3” 不应该出现在 cmets 到 OP 的问题中。期间。
标签: python python-3.x