Python Script
R1 = int(input("Enter the number of rows of matrix1:"))
C1 = int(input("Enter the number of columns of matrix1:"))
# Initialize matrix
matrixA = []
print("Enter elements of matrices one by one:")
# For user input
for i in range(R1): # A for loop for row entries
a =[]
for j in range(C1): # A for loop for column entries
a.append(int(input()))
matrixA.append(a)
# For printing the matrix
for i in range(R1):
for j in range(C1):
print(matrixA[i][j], end = " ")
print()
R2 = int(input("Enter the number of rows of matrix2:"))
C2 = int(input("Enter the number of columns of matrix2:"))
matrixB = []
# For user input
for i in range(R2): # A for loop for row entries
b =[]
for j in range(C2): # A for loop for column entries
b.append(int(input()))
matrixB.append(b)
# For printing the matrix
for i in range(R2):
for j in range(C2):
print(matrixB[i][j], end = " ")
print()
for i in range(R2):
for j in range(C2):
print(matrixA[i][j] + matrixB[i][j], end = " ")
print()
Output
Enter the number of rows of matrix1:3
Enter the number of columns of matrix1:3
Enter elements of matrices one by one:
1
2
3
4
5
6
7
8
9
1 2 3
4 5 6
7 8 9
Enter the number of rows of matrix2:3
Enter the number of columns of matrix2:3
9
8
7
6
5
4
3
2
1
9 8 7
6 5 4
3 2 1
10 10 10
10 10 10
10 10 10