-2
After drawing a number from a list, I need to delete this number from my list. but the message "list index out of range" appears. My error is in the if line. or is there a better way to delete that number? remembering that the other numbers that were not drawn have to stay on the list to be drawn. I have studied the functions of the module Random, but none fits to solve this problem.
import random
import time
Matriz = []
Tamanho_Que_Ficou = 20
Tamanho = 21
Lista_De_Numeros = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
for i in range(3):
Matriz.append([0] * 7)
for i in range(3):
for j in range(7):
Numero = random.choice(Lista_De_Numeros)
Matriz[i][j] = Numero
for k in range(Tamanho):
if Numero == Lista_De_Numeros[k]:
del Lista_De_Numeros[k]
Lista_De_Numeros = [] * Tamanho_Que_Ficou
Tamanho_Que_Ficou = Tamanho_Que_Ficou - 1
Tamanho = Tamanho - 1
print(Matriz)
I’m a beginner in python, but your code was much more practical. I searched and did not find this command "remove". Thanks!
– Dumb