Filling a matrix with values from the keyboard
Let the program receive a two-dimensional array as input, in the form of n
lines, each of which contains m
numbers separated by spaces. How to count them? For example like this:
A=[]
for i in range(n):
A.append(list(map(int, input().split()))) # the list() method creates a list(array)
# from the set of data given in brackets
Or, without using complex nested function calls:
A=[]
for i in range(n):
row = input().split() # read a string with numbers,
# split into elements by spaces (got array row)
for i in range(len(row)):
row[i] = int(row[i]) # each element of list row converted to a number
A.append(row) # append array row to array A