0
我設法讓2個玩家輪流玩,但在第二個玩家輸入她的答案後停止。我想做While循環,但是我很認真地跑出了想法。我把它放在腦海裏,就像我希望兩個玩家一直玩,直到0或3的位置被填滿,但是把它放在代碼中,我真的需要幫助。如何使用while循環滿足許多條件?#
下面是我的病情,但我希望它繼續詢問玩家,直到這些條件都滿足
if list1[0,1,2] == 'x':
print ('Congrats! x won!')
elif (list1 [0] , list2 [0] , list3[0]) == 'x':
print ('Congrats! x won!')
elif (list1 [0] , list2 [1], list3[2]) == 'x':
print ('Congrats! x won!')
elif (list2 [0] , list2 [1], list2[2])== 'x':
print ('Congrats! x won!')
elif (list3 [0] , list3 [0], list3[0]) == 'x':
print ('Congrats! x won!')
elif (list1 [1] , list2 [1], list3[1]) == 'x':
print ('Congrats! x won!')
elif (list1 [2] , list2 [2], list3[2]) == 'x':
print ('Congrats! x won!')
elif (list1 [0] , list2 [1], list3[0]) == 'x':
print ('Congrats! x won!')
elif (list1 [1] , list2 [1], list3[1]) == 'x':
print ('Congrats! x won!')
elif (list1 [2] , list2 [2], list3[2]) == 'x':
print ('Congrats! x won!')
elif (list1 [0] , list2 [0], list3[0]) == 'x':
print ('Congrats! x won!')
elif (list1[0,1,2] == 'o':)
print ('Congrats! o won!')
elif (list1 [0] , list2 [0] ,list3[0]) == 'o':
print ('Congrats! o won!')
elif (list1 [0] , list2 [1], list3[2]) == 'o':
print ('Congrats! o won!')
elif (list2 [0] , list2 [1], list2[2]) == 'o':
print ('Congrats! o won!')
elif (list3 [0] , list3 [0], list3[0]) == 'o':
print ('Congrats! o won!')
elif (list1 [1] , list2 [1], list3[1]) == 'o':
print ('Congrats! o won!')
elif (list1 [2] , list2 [2], list3[2]) == 'o':
print ('Congrats! o won!')
elif (list1 [0] , list2 [1], list3[0]) == 'o':
print ('Congrats! o won!')
elif (list1 [1] , list2 [1], list3[1]) == 'o':
print ('Congrats! o won!')
elif (list1 [2] , list2 [2], list3[2]) == 'o':
print ('Congrats! o won!')
elif (list1 [0] , list2 [0], list3[0]) == 'o':
print ('Congrats! o won!')
else
等待,是一個井字棋有3列,而你檢查是否有人贏了? –
你的任何條件都不會是真的,因爲你正在比較不同的對象。我建議你看看[python教程](https://docs.python.org/2/tutorial/) –
是的,我使用了3個列表。 list1,list2和list3 – sarah