当我运行我的程序时,我收到此错误,但我不知道为什么。错误发生在“if 1 not in c:”行上
Code:
matrix = [
[0, 0, 0, 5, 0, 0, 0, 0, 6],
[8, 0, 0, 0, 4, 7, 5, 0, 3],
[0, 5, 0, 0, 0, 3, 0, 0, 0],
[0, 7, 0, 8, 0, 0, 0, 0, 9],
[0, 0, 0, 0, 1, 0, 0, 0, 0],
[9, 0, 0, 0, 0, 4, 0, 2, 0],
[0, 0, 0, 9, 0, 0, 0, 1, 0],
[7, 0, 8, 3, 2, 0, 0, 0, 5],
[3, 0, 0, 0, 0, 8, 0, 0, 0],
]
a = 1
while a:
try:
for c, row in enumerate(matrix):
if 0 in row:
print("Found 0 on row,", c, "index", row.index(0))
if 1 not in c:
print ("t")
except ValueError:
break
我想知道的是如何修复此错误并仍然使程序正确运行。
提前致谢!