TypeError: argument of type 'int' is not iterable

后端 未结 6 499
既然无缘
既然无缘 2021-01-12 05:42

I am getting this error when I run my program and I have no idea why. The error is occurring on the line that says \"if 1 not in c:\"

Code:

matrix =          


        
6条回答
  •  -上瘾入骨i
    2021-01-12 06:17

    Based on the OP's comment It should print "t" if there is a 0 in a row and there is not a 1 in the row.

    change if 1 not in c to if 1 not in row

    for c, row in enumerate(matrix):
        if 0 in row:
            print("Found 0 on row,", c, "index", row.index(0))
            if 1 not in row: #change here
                print ("t")
    

    Further clarification: The row variable holds a single row itself, ie [0, 5, 0, 0, 0, 3, 0, 0, 0]. The c variable holds the index of which row it is. ie, if row holds the 3rd row in the matrix, c = 2. Remember that c is zero-based, ie the first row is at index 0, second row at index 1 etc.

提交回复
热议问题