lundi 4 janvier 2021

referring to a single element in list of lists [duplicate]

so I have a list of lists (in python 3.8)which is going to be a squared board 40x40 fields. now I want to replace random 100 items with '■'. my code goes like this:

for i in range(1, 100):
    x = random.randint(0, 39)
    y = random.randint(0, 39)
    board[x][y] = '■'

the thing is even the numbers are generated randomly every time the loop runs, it replaces all the elements with the y index in every list. it doesn't matter what is generated as x value.

what am i doing wrong?




Aucun commentaire:

Enregistrer un commentaire