當我運行我的程序時出現此錯誤,我不知道爲什麼。該錯誤發生在,說:「如果1沒有在C:」行TypeError:類型'int'的參數不可迭代
代碼:
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
我想知道的是如何從發生修正這個錯誤的還有節目正確運行。
在此先感謝!
我該如何在沒有錯誤的情況下執行此操作? – chingchong 2011-12-30 01:19:45
你想做什麼? (什麼時候應該打印't'?) – BenH 2011-12-30 01:24:26
如果一行中有0並且行中沒有1,它應該打印「t」。 – chingchong 2011-12-30 01:25:47