我正在做一个简单的程序(只是开个玩笑)。程序需要用户输入yes或no(可以是不同的语言)。但当他输入一个保留字(i。e。关键字)发生错误是因为该关键字在代码中存在一些错误
我的截断代码(可能因为被截断而显得不清楚):
x = input('Enter yes or no (you can do this in different languages...) ')
x = x.lower()
answersYes = ['yes','si','oui','ioe','inde','tak','ja','da']
answersNo = ['no','ayi','che','leai','nie','ne','nein']
if ' ' in x:
print('Input just one word!')
else:
if x in answersYes:
print('You enteres YES!')
elif x in answersNo:
print('You enteres NO!')
else:
print('Sorry, but this isn\'t YES nor NO!')
我在谷歌上搜索了一下,但还没找到运气
谢谢你的回答
附言
只是一个小提示:
当我在basic Python IDLE中用Python运行上层脚本时,没有任何错误,但是当我在Spyder中运行此脚本时,显示了以下消息(当我在no中键入'yes'(“in”是一个保留字)):
File "<ipython-input-49-d1e48c3ddecb>", line 1
yes in no
^
SyntaxError: invalid syntax
我没有错。确保您的spyder已配置python3,或者尝试使用python3 file.py运行 也可以尝试用
raw_input()
替换input()
相关问题 更多 >
编程相关推荐