0
I have ran in to an issue...
So I started a cluedo game on python and I have a problem the generators that generate the murderer and victim have a chance of being the same person so what do I do?
5 Réponses
+ 3
1. Sample the victim.
2. Exclude the victim from the set of characters.
3. Sample murderer.
+ 3
1.shuffle the list.
2. use the first item as the victim, the next or the last item as the murderer.
from random import shuffle
characters = ['Mrs. White', 'Mr. Green', 'Mrs. Peacock', 'Professor Plum', 'Miss Scarlet', 'Colonel Mustard', 'Dr. Black']
shuffle(characters)
print(characters)
victim, murderer, *_ = characters
#or
#victim, *_, murderer = characters
print(f'{victim = }\n{murderer = }')
+ 1
The module is called "random", not "shuffle". You need to import the function "shuffle" from the module "random".
0
It says there's no module named shuffle
0
Ooh ok thanks