-1
Find the first line in the matrix with all positive elements, and the sum of these elements. Reduce all elements to that sum.
Here is my attempt, but in this way add up the positive elements:
matrix = [[-5, -6, 2], [7, 2, 3], [8, 4, -9]]
summ = 0
for i in range(len(matrix)):
pos = False
for j in range(len(matrix[i])):
if matrix[i][j] > 0:
pos = True
summ += matrix[i][j]
if pos:
for i in range(len(matrix)):
for j in range(len(matrix[i])):
matrix[i][j] = summ
print("Sum of the row with all positive elements: ", summ)
for i in matrix:
print(" ",i)
else:
print("There is not a row with all positive elements.")
I didn’t quite understand what your question was, could you write in your words? What error is giving in your code?
– Paulo
Downvote because it’s homework.
– sergiopereira