Search code examples
pythonlistrandominputcounter

Remove "randomized" and "input" values from a procedural list


I recently played the Werewolf game with some friends, in order to ease the Game Master work I wanted to create a simple Python program allowing fast roles randomization.

I'm not a professional nor someone with high Python skills, I just understand how algorithms work so I lack vocabulary to shape my ideas, but I managed to create a working code:

import random

Roles = ['a werewolf', 'the werewolf seer', 'the fool', 'the seer', 'the witch', 'the    hunter', 'the priest', 'cupidon', 'the little girl', 'the bodyguard']
List = []
Counter = 0
Players = int(input("How many player are there ? "))

while Counter < Players:

    print("Player", Counter + 1, end=", ")
    Name = (input("What is your name ? "))
    List.append(Name)
    Counter = Counter + 1

for i in range(Players):

    print(random.choice(List), ", You are", random.choice(Roles))

The problem is, roles and names are randomized, so I can't tell my program to exclude just listed values, therefore some names are duplicated as well as some roles.

I have 3 questions:

  • How can I refer to input values from a list?
  • How can I refer to randomized values from a list?
  • How can I tell my program to remove just listed values (randomized or input) from the list in order to avoid duplicates?

Solution

  • i think this is work for you :)

        import random
    
    Roles = ['a werewolf', 'the werewolf seer', 'the fool', 'the seer', 'the witch', 'the    hunter', 'the priest', 'cupidon', 'the little girl', 'the bodyguard']
    List = []
    Counter = 0
    Players = int(input("How many player are there ? "))
    
    while Counter < Players:
    
        print("Player", Counter + 1, end=", ")
        Name = (input("What is your name ? "))
        List.append(Name)
        Counter = Counter + 1
    
    for i in range(Players):
        rand_names = random.choice(List)
        rand_roles = random.choice(Roles)
        List.remove(rand_names)
        Roles.remove(rand_roles)
        print(rand_names, ", You are", rand_roles)