How to take 2D array input in python
Python code implementation to take 2D array input.
Code:
column_size = int(input("Enter size of column: "))
row_size = int(input("Enter size of row: "))
a = []
for i in range(0, row_size):
b = []
for j in range(0, column_size):
print("Input {0} {1} element of 2d array".format(i, j))
temp = int(input())
b.append(temp)
a.append(b)
print("Print 2D array: ", a)
Value of column size entered: 4
Value of row size entered: 2
Output: The code executed to take input for all the elements of 2D array list and print the 2D array
Enter size of column: 4 Enter size of row: 2 Input 0 0 element of 2d array 1 Input 0 1 element of 2d array 2 Input 0 2 element of 2d array 3 Input 0 3 element of 2d array 4 Input 1 0 element of 2d array 5 Input 1 1 element of 2d array 6 Input 1 2 element of 2d array 7 Input 1 3 element of 2d array 8 [[1, 2, 3, 4], [5, 6, 7, 8]]