试试这个,我想会有用的:import random
x_arr=[]
y_arr=[]
index = 0
pattern = [1,2,6,9,8]
def addTolist(m,n):
x_arr.append(m)
y_arr.append(n)
grid = [[1,2,3],[4,5,6],[7,8,9]] #rows of dots from top to bottom
dot = random.choice(range(1,10)) #random dot from the grid is chosen
guess = 1
while dot!= pattern[index]:
print("Wrong guess",dot)
guess += 1
dot = random.choice(range(1,10))
for i in range(3):
for j in range(3):
if dot == grid[i][j]:
x = i
y = j
break
num = [dot]
print('dot:',dot)
for i in range(4):
index +=1
# every time empty the list
neighbours = []
x_arr=[]
y_arr=[]
#choosing only the ad