【发布时间】:2022-01-20 04:30:13
【问题描述】:
我正在玩井字游戏,我想让Computer 变量永远不要选择Player 输入选择的内容。
from ast import If
import random
from re import X
wordlist = [' ',' ',' '], [' ',' ', ' '], [' ',' ',' ']
wordlist2 = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
def Game():
for element in wordlist:
print(element)
while True:
Player = input()
Computer = random.choice(wordlist2)
#Player
if Player == '1':
wordlist[0][0] = 'x'
if Player == '1':
wordlist2.pop(0)
if Player == '2':
wordlist[0][1] = 'x'
if Player == '2':
wordlist2.pop(1)
if Player == '3':
wordlist[0][2] = 'x'
if Player == '3':
wordlist2.pop(2)
if Player == '4':
wordlist[1][0] = 'x'
if Player == '4':
wordlist2.pop(3)
if Player == '5':
wordlist[1][1] = 'x'
if Player == '5':
wordlist2.pop(4)
if Player == '6':
wordlist[1][2] = 'x'
if Player == '6':
wordlist2.pop(5)
if Player == '7':
wordlist[2][0] = 'x'
if Player == '7':
wordlist2.pop(6)
if Player == '8':
wordlist[2][1] = 'x'
if Player == '8':
wordlist2.pop(7)
if Player == '9':
wordlist[2][2] = 'x'
if Player == '9':
wordlist2.pop(8)
#Computer
if Computer == '1':
wordlist[0][0] = 'o'
if Computer == '2':
wordlist[0][1] = 'o'
if Computer == '3':
wordlist[0][2] = 'o'
if Computer == '4':
wordlist[1][0] = 'o'
if Computer == '5':
wordlist[1][1] = 'o'
if Computer == '6':
wordlist[1][2] = 'o'
if Computer == '7':
wordlist[2][0] = 'o'
if Computer == '8':
wordlist[2][1] = 'o'
if Computer == '9':
wordlist[2][2] = 'o'
Game()
错误
发生异常:IndexError pop index out of range
【问题讨论】:
-
我建议你开始接受你的答案...