我一直在尝试制作一个包含 2 个列表的程序。第一个列表是问题,其中存储了我必须将它们与用户输入进行比较的数据。如果用户输入与列表(问题)中的项目完全相同,则打印第二个列表中的其他数据。例如:
Questions=["hello","yellow","horse"]
Ans=["world","I pref red","I pref dog"]
# now if input of user is something from the Questions list, it will print # from Ans
# if input --> yellow
# then --> print(Ans[1])
我写的代码是这样的:
x = len(Questions)
leng = int(x / 2)
quest = str(input('Which your question: '))
while(quest!='@'):
counter = 0
if(quest == Questions[counter]):
print(Ans[counter])
else:
counter+=1
while(quest != Questions[counter] and counter<x):
counter+=1
print(Ans[counter])
quest = str(input('Which your question: '))
出于某种原因,我出现了这个错误:list index out of range line 244, in while(quest != Questions[counter] and counter
慕桂英3389331
千万里不及你
暮色呼如
相关分类