Python program to add two matrices

Given size N, for NxN and Matrix A, Matrix B, perform the sum of two matrices and print the resultant matrix.

Output:

Enter the value of N for N x N: 3
Enter the elements of matrix A:
1 2 3
4 5 6
7 8 9
Enter the elements of matrix B:
9 8 7
6 5 4
3 2 1
Resultant matrix is: (matrixA + matrixB)
10 10 10
10 10 10
10 10 10

Python Implementation:

matrixA = []
matrixB = []
print "Enter the value of N for N x N:"
N = int(raw_input())
print "Enter the elements of matrix A:"
for i in range(N):
 line = raw_input()
 list = map(int,line.split())
 matrixA.append(list)
print "Enter the elements of matrix B:"
for i in range(N):
 matrixB.append(map(int,raw_input().split()))

# add two matrices
print "Resultant matrix is: (matrixA + matrixB)"
for i in range(N):
 for j in range(N):
  print matrixA[i][j] + matrixB[i][j],
 print ""