Find the first line in the array with all the positive elements, and the sum of these elements. Reduce all elements to this 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.")