Input numbers in nested list and find the sum of each column in Python
Lists - Question 11
In this question, we will see how to input numbers in a 3X3 integer matrix (nested list) and find the sum of each column separately in Python programming. To know more about lists click on the lists lesson.
Q11) Write a program in Python to input numbers in a 3X3 integer matrix (nested list) and find the sum of each column separately.
Program
a=[[],[],[]]
r=0;c=0;cs=0
print('Enter 9 numbers')
for r in range(3):
for c in range(3):
a[r].append(int(input()))
for r in range(3):
cs=0
for c in range(3):
print(a[r][c],end=' ')
cs=cs+a[c][r]
print(' Column Sum =',cs)
Output
Enter 9 numbers 18 12 72 10 15 45 38 5 64 18 12 72 Column Sum = 66 10 15 45 Column Sum = 32 38 5 64 Column Sum = 181