0% found this document useful (0 votes)
2 views

addition_matrix

The document is a Python script that prompts the user to input the dimensions and values for two matrices, A and B. It checks if the matrices can be added based on their dimensions and, if possible, performs the addition and displays the resulting matrix. If the dimensions do not allow for addition, it informs the user that the operation is not possible.

Uploaded by

gopichand56780
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

addition_matrix

The document is a Python script that prompts the user to input the dimensions and values for two matrices, A and B. It checks if the matrices can be added based on their dimensions and, if possible, performs the addition and displays the resulting matrix. If the dimensions do not allow for addition, it informs the user that the operation is not possible.

Uploaded by

gopichand56780
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

m = int(input('Number of rows for matrix - A, m = '))

n = int(input('Number of columns for matrix - A, n = '))

p = int(input('Number of rows for matrix - B, p = '))

q = int(input('Number of columns for matrix - B, q = '))

A = []

B = []

res = [[0 for i in range(n)] for j in range(m)]

if (m == p and n == q):

print("Enter values for matrix - A")

for i in range(0, m):

acol = []

for j in range(0, n):

print("Entry in row:", i + 1, "column:", j + 1)

c = int(input())

acol.append(c)

A.append(acol)

print("Enter values for matrix - B")

for i in range(0, p):

bcol = []

for j in range(0, q):

print("Entry in row:", i + 1, "column:", j + 1)

d = int(input())

bcol.append(d)

B.append(bcol)

for i in range(0, p):


for j in range(0, q):

res[i][j] = A[i][j] + B[i][j]

print("Matrix a =", A)

print("Matrix b =", B)

print("Addition of two matrices =", res)

else:

print("Addition is not possible")

You might also like