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?

3rd May 2025, 8:26 AM
Eben Erasmus
Eben Erasmus - avatar
5 Antworten
+ 3
1. Sample the victim. 2. Exclude the victim from the set of characters. 3. Sample murderer.
3rd May 2025, 8:53 AM
Lisa
Lisa - avatar
+ 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 = }')
3rd May 2025, 11:03 AM
Bob_Li
Bob_Li - avatar
+ 1
The module is called "random", not "shuffle". You need to import the function "shuffle" from the module "random".
28th May 2025, 4:20 PM
Lisa
Lisa - avatar
0
It says there's no module named shuffle
28th May 2025, 4:15 PM
Eben Erasmus
Eben Erasmus - avatar
0
Ooh ok thanks
29th May 2025, 4:55 PM
Eben Erasmus
Eben Erasmus - avatar