Find the sum of each row of matrix of size m x n. For example for the following matrix output will be like this :

Sum of row 1 = 32
Sum of row 2 = 31
Sum of row 3 = 63

Source Code

n = int(input("Enter the number of rows:")) 
m = int(input("Enter the number of columns:")) 
  
matrix = [] 

print("Enter values in matrix :") 

# For user input 
for i in range(n):
    data =[] 
    for j in range(m):
         data.append(int(input())) 
    matrix.append(data) 

# For printing the matrix 
for i in range(n): 
    for j in range(m): 
        print(matrix[i][j], end = " ") 
    print()


# For printing row wise sum 
for i in range(n):
    sum = 0
    for j in range(m): 
        sum = sum + matrix[i][j]
    print('Sum of row',i+1,':',sum) 

Output

Enter the number of rows:3
Enter the number of columns:4
Enter values in matrix :
2
11
7
12
5
2
9
15
8
3
10
42
2 11 7 12
5 2 9 15
8 3 10 42
Sum of row 1 : 32
Sum of row 2 : 31
Sum of row 3 : 63