lundi 22 mai 2017

Changing values of a matrix randomly (Python)

The matrix is 15x15, and I need to randomly add values to it. Either if a person is dead or alive. For this I typed:

class Individuo:
def __init__(self, vivo, representacion):
    self.vivo = False
    self.representacion = representacion
p_vivo = Individuo(True, "*")
p_muerto = Individuo(False, "#")

Then, I tried to do this to insert it randomly into the matrix:

  for sublistas in matriz:
     for espacios in matriz:
        ran = random.choices(p_vivo, p_muerto)
           matriz.append(ran)

I get an error on:

ran = random.choices(p_vivo, p_muerto)

How can I add these values to a matrix randomly?




Aucun commentaire:

Enregistrer un commentaire