I am working on a homework program, where I need to create a matrix, I did the function that takes an array with some records (that I previously create) as a parameter, but when I create a high number of records, for instance: 100 records, I get the list index out of range
array creation:
def crearVector(n):
vec = [None] * n
for i in range(len(vec)):
codigo = random.randint(1, 1000)
precio = round(random.uniform(1, 100000), 2)
ubicacion = random.randint(1, 23)
estado = random.randint(0, 1)
cantidad = random.randint(0, 1000)
puntuacion = random.randint(1, 5)
publicacion = Publicacion(codigo, precio, ubicacion, estado, cantidad, puntuacion)
vec[i] = publicacion
return vec
array creation function calling:
def test():
n = validateHigherThan(0)
vec = crearVector(n)
matrix creation and showing function:
mat = crearMatriz(vec)
forma = int(input("How would you like to show the matrix?(0: matrix, 1: list): "))
if forma == 1:
mostrarMatrizLista(mat)
elif forma == 0:
mostrarMatriz(mat)
matrix creation:
def crearMatriz(vec):
mat = [[0] * 5 for i in range(23)]
for i in range(len(vec)):
fil = vec[i].ubicacion
col = vec[i].puntuacion-1
mat[fil][col] += 1
return mat
23increarMatriz