求助】判断语句无效,加了flag也还是不行。
代码如下:def solve(sudoku):
flag = 0
list_a = reduce_vr(sudoku)
list_temp = []
for i in range(9):
for j in range(9):
if len(list_a[i][j]) != 1:
flag = 1
else:
break
if flag == 1:
list_temp = trial(sudoku)
print("1")
else:
list_temp = list_a
print("2")
return list_temp
run结果如下:
please input your sudoku question:000502000016000080000000000070030010060000000500009000030080000000000200700000509
2
[[8], [9], [4, 7], [5], [1, 4, 6, 7], [2], [1, 3, 4, 6, 7], [3, 4, 6, 7], [1, 4, 7]]
[[2], [1], [6], [3, 4, 7], [9], [3, 4, 7], [3, 4, 7], [8], [5]]
[[3], [5], [4, 7], [1, 4, 6, 7], [1, 4, 6, 7], [8], [1, 4, 6, 7], [9], [2]]
[[4], [7], [2], [8], [3], [5], [9], [1], [6]]
[[1], [6], [9], [4, 7], [2], [4, 7], [8], [5], [3]]
[[5], [8], [3], [1, 4, 6, 7], [1, 4, 6, 7], [9], [4, 7], [2], [4, 7]]
[[9], [3], [5], [2], [8], [1, 4, 6, 7], [1, 4, 6, 7], [4, 6, 7], [1, 4, 7]]
[[6], [4], [1], [9], [5], [3, 7], [2], [3, 7], [8]]
[[7], [2], [8], [1, 3, 4, 6], [1, 4, 6], [1, 3, 4, 6], [5], [3, 4, 6], [9]]
Process finished with exit code 0