mardi 1 juin 2021

Python : Randomly choose a boolean from an array and change its value

I was wondering if it was possible to create a code like the one quoted.

I mean if it is possible to create an array with booleans (False), choose only one (randomly) and change its value (to True) and then be able to use it?

The first random choice should only be done once, when the program is launched.

Gentleman = False
Daughter = False
Madam = False

character_list = [Gentleman, Daughter, Madam] # an array with the bools above

for character in characters_list:
    character = random.choice(characters_list) # Randomly pick a character from the list
    character = True # Set the character as True

    if Madam == True:
        ...
        Madam = False
        Daughter = True
        ...

    if Gentleman == True:
        ...
        Gentleman = False
        Madam = True
        ...

    if Daughter == True:
        ...
        Daughter = False
        Gentleman = True
        ...

PS: I know my code is wrong but it's just to try to illustrate what I would like to do

Thank you for your help




Aucun commentaire:

Enregistrer un commentaire