def vencedor_linha(t):
if (t[0]=='X' and t[1] and t[2]=='X') or (t[3]=='X' and t[4]=='X' and t[5]=='X') or (t[6]=='X' and t[7]=='X' and t[8]=='X'):
print("'X'")
return True
elif (t[0]=='O' and t[1] and t[2]=='O') or (t[3]=='O' and t[4]=='O' and t[5]=='O') or (t[6]=='O' and t[7]=='O' and t[8]=='O'):
print("'O'")
return True
else:
return False
def vencedor_coluna(t):
if (t[0]=='X' and t[3] and t[6]=='X') or (t[1]=='X' and t[4]=='X' and t[7]=='X') or (t[2]=='X' and t[5]=='X' and t[8]=='X'):
print("'X'")
return True
elif (t[0]=='O' and t[3] and t[6]=='O') or (t[1]=='X' and t[4]=='O' and t[7]=='O') or (t[2]=='O' and t[5]=='O' and t[8]=='X'):
print("'O'")
return True
else:
return False
def vencedor_diagonal(t):
if (t[0]=='X' and t[4] and t[8]=='X') or (t[6]=='X' and t[4]=='X' and t[2]=='X'):
print("'X'")
return True
elif (t[0]=='O' and t[4] and t[8]=='O') or (t[6]=='X' and t[4]=='O' and t[2]=='O'):
print("'O'")
return True
else:
return False
def determina_vencedor(t):
if vencedor_coluna(t):
return vencedor_coluna
elif vencedor_linha(t):
return vencedor_linha
elif vencedor_diagonal(t):
return vencedor_diagonal
else:
return False
所以,如果我们使用:
test1=('O',' ',' ',' ','O',' ',' ',' ','O')
和
test2=(' ',' ',' ','X',' ',' ',' ',' ',' ')
它应该返回我,determina_vencedor(test1)
->'O'
和determina_vencedor(test2)
->False
一切都很好test2
,问题是它"'O', function vencedor_diagonal at 0x0000000002C29A48"
在 test2 给了我。
怎么了?!帮我弄清楚!