I would like to create a matrix MxN. This matrix gets the inputs from the user. I would like to use defensive programming such that the elements of the matrix have not the digit 2. For example the user should not use integers like 12,20,21,22,...32,42,102,... as an input for the matrix. My attempt is the following, but I do not know how to create this conditions with the digit 2.
M = int(input("Enter number of rows"))
N = int(input("Enter number of columns"))
count = 1
matrix = []
for i in range(M):
list = []
for j in range(N):
list.append(count)
count += 1
matrix.append(list)
I created this matrix but I do not know how to add the condition with the restriction in the digits as an input.
The easiest option I can think of is to keep the input of row and col as strings and check if they contain a
2before proceeding.