L
L
lox2562020-11-11 18:42:46
MySQL
lox256, 2020-11-11 18:42:46

I get the error UnboundLocalError: local variable 'xod' referenced before assignment, how to fix it?

Tic-tac-toe code, although I compiled it myself and most likely it is not working now. Only unfortunately I can not finish this game because an error pops up.
code:
print('-----')
print('/',1,'/',2,'/',3,'/')
print('--- ----------')
print('/',4,'/',5,'/',6,'/')
print('----------- --')
print('/',7,'/',8,'/',9,'/')
print('-------------')
a=' '
b=' '
c=' '
d=' '
e=' '
f=' '
g=' '
h=' '
i=' '
XorO='X'
print('/',d,'/',e,'/',f,'/')
print('-------------')
print('/',g, '/',h,'/',i,'/')
print('-------------')
plant_player(x)
def plant_player(x):
name=int(input( ))
if xod%2==0:
XorO='O'
else:
XorO='X'
if name==1 and a==' ':
a==XorO
elif name==2 and b==' ':
b==XorO
elif name==3 and c==' ':
c==XorO
elif name==4 and d==' ':
d==XorO
elif name==5 and e==' ':
e= =XorO
elif name==6 and f==' ':
f==XorO
elif name==7 and g==' ':
g==XorO
elif name==8 and h==' ':
h==XorO
elif name==9 and i==' ':
i==XorO
xod+=1
check_win(x)
def check_win(x):
win=[(a,b,c),(d,e,f),(g ,h,i),(a,d,g),(b,e,h),(c,f,i),(a,e,i),(c,e,g)]
for i in win :
if i[0]==i[1]==i[2]=='X':
print('First player wins!')
return False
elif i[0]==i[1]==i[ 2]=='O':
print('Player 2 wins!')
return False
board(x)
plant_player(1)

error:

Traceback (most recent call last):
file "KH 256 m.py", line 64, in
plant_player(1)
file "KH 256 m.py", line 30, in plant_player
if xod%2==0:

UnboundLocalError : local variable 'xod' referenced before assignment

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nozzy, 2016-07-26
@turboj55

select
t1.name,
group_concat(t3.ingredient separator ',') as ingredient
from Pizza t1
inner join Pizza_Ingredients t2 on t2.pizza_id = t1.id
inner join Ingredients t3 on t3.id = t2.ingredient_id
group by t1.name

M
Maxim Siomin, 2020-11-11
@lox256

at the beginning of the plant_player() function, write the line
global xod

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question