136. Python Program to find Row sum and Column sum of a given Matrix.
How does this program work?
- In this program we are going to learn about how to find Row sum and Column sum of given matrix using Python.
- Elements can be stored in a variable using arrays. Declare variable sumRow and sumCol, and Initialize with 0.
- After that by using the forloop condition we find the Rowsum and Columnsum of given matrix.
Here is the code
a=[]
n=int(input("Enter the size of the matrix: "))
print("Enter the elements: ")
for i in range(n):
row=[]
for j in range(n):
row.append (int(input()))
a.append(row)
print(a)
print("Display an array In Matrix Form: ")
for i in range ( n ):
for j in range(n):
print(a[i][j], end=" ")
print()
rows = len(a);
cols = len(a[0]);
for i in range(0, rows):
r = 0;
for j in range(0, cols):
r = r + a[i][j];
print("Sum of " + str(i+1) +" row: " + str(r));