Python 如何检查子数组中是否有匹配的元素集
我正在做一个tic-tac-toe应用程序,我想知道是否有一种方法可以创建一个函数来检查电路板并确定是否有人赢了? 我还想知道如何优化我的一些代码,因为,是的,我知道这是令人难以置信的草率。 另外,我使用Python3.9.5来实现这一点,没有其他语言 ''' '''Python 如何检查子数组中是否有匹配的元素集,python,arrays,optimization,undefined,sub-array,Python,Arrays,Optimization,Undefined,Sub Array,我正在做一个tic-tac-toe应用程序,我想知道是否有一种方法可以创建一个函数来检查电路板并确定是否有人赢了? 我还想知道如何优化我的一些代码,因为,是的,我知道这是令人难以置信的草率。 另外,我使用Python3.9.5来实现这一点,没有其他语言 ''' ''' tic_tac_toe =[ [[0],[0],[0],[0]], [[0],[0],[0],[0]], [[0],[0],[0],[0]], [[0],[0],[0],[0]], ] pr
tic_tac_toe =[
[[0],[0],[0],[0]],
[[0],[0],[0],[0]],
[[0],[0],[0],[0]],
[[0],[0],[0],[0]],
]
print(tic_tac_toe[1][1:4])
print(tic_tac_toe[2][1:4])
print(tic_tac_toe[3][1:4])
while True:
print("where do you want to put X")
while True:
try:
print("y-axis")
input1 = int(input())
print("x-axis")
input2 = int(input())
if "O" in tic_tac_toe[input1][input2]:
print("there is already a varible there")
elif "X" in tic_tac_toe[input1][input2]:
print("there is already a varible there")
elif input1 == 0:
print("out of range")
elif input2 == 0:
print("out of range")
else:enter code here
tic_tac_toe[input1][input2] = "X"
print(tic_tac_toe[1][1:4])
print(tic_tac_toe[2][1:4])
print(tic_tac_toe[3][1:4])
break
except:
print("out of range")
print("where do you want to put O")
while True:
try:
print("y-axis")
input3 = int(input())
print("x-axis")
input4 = int(input())
if "X" in tic_tac_toe[input3][input4]:
print("there is already a varible there")
elif "O" in tic_tac_toe[input3][input4]:
print("there is already a varible there")
elif input3 == 0:
print("out of range")
elif input4 == 0:
print("out of range")
else:
tic_tac_toe[input3][input4] = "O"
print(tic_tac_toe[1][1:4])
print(tic_tac_toe[2][1:4])
print(tic_tac_toe[3][1:4])
break
except:
print("out of range")