Python Online Compiler
Example: Python Program to Find the Sum of Each Row and Each Column of a Matrix
C
C++
C#
Java
Python
PHP
main.py
STDIN
Run
# Python Program to Find the Sum of Each Row and Each Column of a Matrix print ("-----Enter the number of rows & columns of the matrix-----") # These are the matrix's dimension x = int (input ()) y = int (input ()) a, sum = [], 0 print ("\n-----Enter the co-efficients of the matrix-----") for i in range (x): a.append([]) for j in range (y): a[i].append(int (input ())) print (end="\n") # This statement will compute the # sum of the matrix's rows elements for i in range (x): for j in range (y): sum = sum + a[i][j] print ("The Sum of the ", i, " position row is = ", sum) sum = 0 print (end="\n") sum = 0 # This statement will compute the # sum of the matrix's columns elements for j in range (y): for i in range (x): sum = sum + a[i][j] print ("The Sum of the ", j, " position column is = ", sum) sum = 0
4 3 12 23 12 34 12 43 34 53 12 56 34 23
Output
Clear
ADVERTISEMENTS