Input numbers in nested list and find the sum of each row in Python
Lists - Question 10
In this question, we will see how to input numbers in a 3X3 integer matrix (nested list) and find the sum of each row separately in Python programming. To know more about lists click on the lists lesson.
Q10) Write a program in Python to input numbers in a 3X3 integer matrix (nested list) and find the sum of each row separately.
Program
a=[[],[],[]]
r=0;c=0;rs=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):
rs=0
for c in range(3):
print(a[r][c],end=' ')
rs=rs+a[r][c]
print(' Row Sum =',rs)
Output
Enter 9 numbers 5 74 3 2 63 21 7 19 24 5 74 3 Row Sum = 82 2 63 21 Row Sum = 86 7 19 24 Row Sum = 50