这是我程序的一部分的简化版本:
for i in range(5):
turn1l = []
turn1 = raw_input("Enter Value Using the format \'x,y\' : ")
turn1l.append(turn1)
def winnerchecker():
if "1,1" in turn1l and "1,2" in turn1l and "1,3" in turn1l:
print xplayer, "YOU HAVE WON! GG TO ", name
raise SystemExit()
winnerchecker()
出于某种原因,每次我输入“1,1”然后“1,2”然后“1,3”它不会停止该程序,它会继续。如何让它停止,有什么方法我不知道吗?谢谢!
答案 0 :(得分:2)
不要在循环的每次迭代开始时重新初始化列表turn1l
:
for i in range(5):
turn1l = []
相反,请列出一次:
turn1l = []
for i in range(5):
...