0
I have trouble with the job players()
, because I can’t increment the variable n
, the function is only returning "X"
. I know it sounds pretty simple, but I can’t identify the problem. Can anyone help me?
def players():
n = 0
if n % 2 == 0:
n = n + 1
return 'X'
else:
n = n + 1
return 'O'
def play():
gon = 0
while gon != 9:
pos = input('Insira a posição que deseja jogar: ')
if pos == '1':
paper[0][0] = players()
gon += 1
elif pos == '2':
paper[1][0] = players()
gon += 1
elif pos == '3':
paper[2][0] = players()
gon += 1
elif pos == '4':
paper[3][0] = players()
gon += 1
elif pos == '5':
paper[4][0] = players()
gon += 1
elif pos == '6':
paper[5][0] = players()
gon += 1
elif pos == '7':
paper[6][0] = players()
gon += 1
elif pos == '8':
paper[7][0] = players()
gon += 1
elif pos == '9':
paper[8][0] = players()
gon += 1
else:
print('Dígito inválido! Tente novamente.')
print(' %s | %s | %s ' % (paper[0][0],paper[1][0],paper[2][0]))
print('-----------')
print(' %s | %s | %s ' % (paper[3][0],paper[4][0],paper[5][0]))
print('-----------')
print(' %s | %s | %s ' % (paper[6][0],paper[7][0],paper[8][0]))
if gon == 9:
print('\n Empate!')
paper = [[' '],[' '],[' '],
[' '],[' '],[' '],
[' '],[' '],[' ']]
print('Bem-vindo ao Jogo da Velha!')
print('Cliente é X;')
print('Servidor é O.')
play()
Its function
players()
this setando every time then
zero, whenever it is called, thatn = 0
can’t be in there– Christian Beregula