I'm new to Python and I'm trying to translate some code from c++ to python, but I can't make letters be random in both dimensions of a list. This is my function
def chooseLetter():
lower_alphabet=['a', 'b', 'c', 'd']
element=''
if (random.randint(0,2)==1):
element = element + random.choice(lower_alphabet)
return element
else:
return ' '
for i in range(9):
for j in range(9):
board[i][j]=chooseLetter()
I get something like this
[[' ', 'b', 'b', 'c', ' ', ' ', ' ', ' ', ' '], [' ', 'b', 'b', 'c', ' ', ' ', ' ', ' ', ' '], ...
I tried system random and some datetime modules, but I am not that familiar with all that and it doesn't really work. ' ' are supposed to be there, I don't want letters to be everywhere.
Aucun commentaire:
Enregistrer un commentaire