嗯。这是我我把你的问题一起:
1)你有几个措辞数字和答案:
round1questions=["two thousand and two", "one thousand and one"] # and more
round2answers=["2002", "1001"] # and more
2)从我对你的问题的理解,在每一轮,十个问题被问和TEN答案被采取...
3)如果任何问题得到了错误的答案,在另一回合中再次询问错误回答的问题。
因此,这里是我的问题的解决方案:
questions=["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]
answers=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
ans_correct=[None, None, None, None, None, None, None, None, None, None]
#You can use this method to add "None" to the ans_correct list if you have many questions
#and you're too lazy to write so many "None"s.
'''
ans_correct=[]
for each in questions:
ans_correct.append(None)
'''
while (False in ans_correct) or (None in ans_correct):
for each in questions:
if ans_correct[questions.index(each)]!=True:
ans=str(input("What is the numerical form of %s?" %(each)))
if ans==answers[questions.index(each)]:
print("Correct!")
ans_correct[questions.index(each)]=True
else:
print("Wrong!")
ans_correct[questions.index(each)]=False
基本上,上面的代码会不断地问你的问题,直到所有的答案都是正确的。如果有任何问题被错误地回答,他们会再次被问到。
最好使用'while x <10'。这样,如果'x'恰好为11,由于附加到列表中的项目数量,程序不会耗尽内存。还记得增加'x' – smac89