1# A basic code for matrix input from user
2
3R = int(input("Enter the number of rows:"))
4C = int(input("Enter the number of columns:"))
5
6# Initialize matrix
7matrix = []
8print("Enter the entries rowwise:")
9
10# For user input
11for i in range(R): # A for loop for row entries
12 a =[]
13 for j in range(C): # A for loop for column entries
14 a.append(int(input()))
15 matrix.append(a)
16
17# For printing the matrix
18for i in range(R):
19 for j in range(C):
20 print(matrix[i][j], end = " ")
21 print()
1If you want to take n lines of input where each line contains m space separated integers like:
2
31 2 3
44 5 6
57 8 9
6
7a=[] // declaration
8for i in range(0,n): //where n is the no. of lines you want
9 a.append([int(j) for j in input().split()]) // for taking m space separated integers as input