To be honest, you have written something very strange.
The code a = [] creates a list, and from the condition it is assumed that this will be a matrix (that is, a list of lists). A 10 × 10 matrix of zeros can be formed using a generator:
a = [[0]*10 for i in range(10)]
Now its elements can be accessed as a[i][j] . Further, with its bypass everything is clear, two nested loops. Everything is good here. But it’s completely unclear from your code what you wanted to do with each element:
a[i][j]=int(a[i][j])
from the position [i, j] matrix a takes a value, converts it to a number and saves it to the same position. Perhaps you needed some other effect. If we assume that you were going to initialize the matrix element in this way, then now it is not necessary, since this has already been done. Go ahead:
a.append(random.randint(0,999))
This construction adds an element to the list (at its end!) By writing a random number there. And this means that it changes the size of the list, which is unacceptable in this case. If you thus wanted to write a random number as the current element, you had to refer to the current element and not create a new one:
a[i][j] = random.randint(0,999)
The next line you reset the value of the variable count . So nothing will come out, you do it at each iteration of the loop (and therefore never count 1 is stored in the count ), and if you want to bypass all the elements of the matrix and count their number, the counter reset code must be removed from the loop by placing it . With the conditional operator everything is fine.
So, if I correctly understood what was meant (although for me, this is a strange interpretation of the problem condition), the code will turn out like this:
import random a = [[0]*10 for i in range(10)] count = 0 for i in range(10): for j in range(10): a[i][j] = random.randint(0,999) if 10 <= a[i][j] <= 99: count += 1 print(a) print('количество двузначных чисел', count)
Or, if you write shorter:
a = [[random.randint(0,999) for i in range(10)] for j in range(10)] count = sum([1 for i in range(10) for j in range(10) if 10 <= a[i][j]<= 99])