I'm making a Tic Tac Toe game on python so far I've come up with a pretty solid code but I'm getting an error at one point that I am unable to fix.
Here's the code:
from random import randint
List=[[0,0,0],[0,0,0],[0,0,0]]
def board(List):
print('=== Tic Tac Toe ===')
for i in range(3):
print(' ',List[i][0],' ',List[i][1],' ',List[i][2])
def usr_choice(i,f,List):
while List[i][f]!=0:
i,f =eval(input('Please enter correct choice i or f: '))
List[i][f]=2
def comp_choice(List):
i=randint(0,2),f=randint(0,2)
while List[i][f]!=0:
i=randint(0,2),f=randint(0,2)
List[i][f]=1
def decision(List):
if [List[i][i] for i in range(3)]==[2,2,2] or \
[List[2-i][i] for i in range(3)]==[2,2,2]:
print('You win!')
return True
elif[List[i][i] for i in range(3)]==[1,1,1] or \
[List[2-i][i] for i in range(3)]==[1,1,1]:
print('You lose!')
return True
else:
for i in range(3):
if [List [i][:]for i in range(3)]==[2,2,2] or \
[List[f][i] for j in range(3)]==[2,2,2]:
print('You win!')
return True
elif [List [i][:]for i in range(3)]==[1,1,1] or \
[List[f][i] for j in range(3)]==[1,1,1]:
print('You lose!')
return True
This is the error I am receiving under def comp_choice(List):
i=randint(0,2),j=randint(0,2)
^
SyntaxError: cannot assign to function call
To declare multiple variables in the same assignment, do:
i, j = randint(0, 2), randint(0, 2)
To declare multiple variable in different assignments but in the same row, do:
i = randint(0, 2); j = randint(0, 2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.