139. Python Program to print Outer Square Elements of a given Matrix.
How does this program work?
- In this program we are going to learn about how to print Outer Square elements of a given matrix using Python.
- Elements are stored in array variable. Here we used 4*4 matrix to display outer square elements of given matrix.
Here is the code
a=[]
n=int(input("Enter the size of the matrix: "))
print("Enter the elements: ")
for i in range(n):
row=[]
for j in range(n):
row.append(int(input()))
a.append(row)
print(a)
print("Display an array In Matrix Form: ")
for i in range(n):
for j in range(n):
print(a[i][j], end=" ")
print()
print("Outer Square of the matrix: ")
for i in range(n):
for j in range(n):
if (i == 0):
print(a[i][j], end= " ")
elif (i == n-1):
print(a[i][j], end= " ")
elif (j == 0):
print(a[i][j], end= " ")
elif (j == n-1):
print(a[i][j], end= " ")
else:
print(end = " ")
print(" ")