An exercise error


Why is my solution is wrong?
Screenshot 2020-12-25 160055
and I couldn’t understand the answer.

:grinning: :grinning: :grinning: I have found another solution.

Hi Maho

You have already found out, the issue is with your code
x.append(row(i)) .

In the solution code,num_rows is 3 and num_cols is 4. So the first for loop will iterate through each row and the second for loop will traverse through each column of the current row.
hence, matrix[row][col] will fetch us each and every item in the matrix.
matrix[0][0] is 0, matrix[0][1] is 9, matrix[0][2] is 5, matrix[0][3] is 4 and so on.
total += matrix[row][col] will get us the sum of all the values.

Hope it’s clear now.
Thanks.

1 Like