【发布时间】:2014-01-22 20:06:43
【问题描述】:
我正在使用 for 循环制作一个使用 for 循环的超级简单的程序,该程序会询问您 3 次您的爱好并将您的答案附加到一个名为 hobbies 的列表中:
hobbies = []
for me in range(3):
hobby=input("Tell me one of your hobbies: ")
hobbies.append(hobby)
例如,如果我给它“编码”,它将返回:
Traceback (most recent call last):
File "python", line 4, in <module>
File "<string>", line 1, in <module>
NameError: name 'coding' is not defined
请注意,如果我使用 Python 2.7 并改用 raw_input,则程序运行良好。
【问题讨论】:
标签: python list for-loop append nameerror