Dremendo Tag Line

Input numbers in nested list and check symmetric matrix or not in Python

Lists - Question 15

In this question, we will see how to input numbers in a 3X3 integer matrix (nested list) and check whether it is a symmetric matrix or not in Python programming. To know more about lists click on the lists lesson.

Q15) Write a program in Python to input numbers in a 3X3 integer matrix (nested list) and check whether it is a symmetric matrix or not. Symmetric matrix is such a matrix whose row elements are exactly same as column elements.

Double Dimension Array Question 10

Program

a=[[],[],[]]
r=0;c=0;x=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):
    for c in range(3):
        print(a[r][c],end=' ')
        if a[r][c]==a[c][r]:
            x=x+1
    print()

if x==9:
    print('Symmetric Matrix')
else:
    print('Not Symmetric Matrix')

Output

Enter 9 numbers
2
4
5
4
9
12
5
12
15
2 4 5
4 9 12
5 12 15
Symmetric Matrix
video-poster