Sunday, March 3, 2019

Addition of Matrix m*n - Python3

print ("Enter n for m*n matrix")
m=int(input('Enter m: '))
n=int(input('Enter n: '))
mat1=[]
mat2=[]
mat3=[]
l=[]
print ("Enter matrix 1 : ")
for i in range(n):
    l=[]
    for j in range(m):
        l.append(int(input()))
    mat1.append(l)

print ("Enter matrix 2 : ")
for i in range(n):
    l=[]
    for j in range(m):
        l.append(int(input()))
    mat2.append(l)
    

for i in range(n):
    l=[]
    for j in range(m):
        l.append(mat1[i][j]+mat2[i][j])
    mat3.append(l)
    
print ("Matrix 1 : ",mat1)
print ("Matrix 2 : ",mat2)
print ("Addition of Matrix 1 and Matrix 2 is",mat3)


ScreenShot:

No comments:

Post a Comment