mardi 31 août 2021

Could I make my program choose randomly between variables (all integers) in a list, with it returning the variable, not the value?

So I have a list of variables (all being integers). I would want to randomly choose one of these variables, but make it so that it returns the actual variable, not the value.

for example:

list = [a, b, c, d]

(with all of them equal to 0)

print(random.choice(list)) 

would return 0, while I want it to return a, b, c or d;

So that if I write :

random.choice(list) += 2

It would update one of these variables.




Aucun commentaire:

Enregistrer un commentaire