52. Python Program to Display 9 elements in 3x3 Matrix Format.
How does this program work?
- In this program we are going to learn about how to display 9 elements in 3x3 matrix format using Python.
- First 9 numbers can be stored in one variable using arrays.
- After that we can followed by the below logic then we get the Output in matrix format.
Here is the code
r = int(input("Enter the number of rows:"))
c = int(input("Enter the number of columns:"))
matrix = []
print("Enter the elements of matrix:")
# For user input
for i in range(r): # A for loop for row elements
a = []
for j in range(c): # A for loop for column elements
a.append(int(input()))
matrix.append(a)
# For printing the matrix
for i in range(r):
for j in range(c):
print(matrix[i][j], end=" ")
print()