From f4b2d95e0220e4ea7fbb3d026c5c3f005f598b3c Mon Sep 17 00:00:00 2001 From: mbhatti4 Date: Tue, 11 Nov 2025 14:46:14 -0500 Subject: [PATCH] I edited dice_stats.py to add the additional trials You can use Classes to simmulate many experiments. Just as we used it to roll dice, we could also simulate randomizer picking numbers to then do something with. You could flip coins and then have outcomes such as "three heads in a row". You can also use it to simulate shuffle a deck of cards and have it simulate giving them out. --- dice_stats.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..6f1a7a7 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -19,15 +19,40 @@ class FiveDice: return False return True + + def is_three_of_a_kind(self): + faces = self.faces() + for value in set(faces): + if faces.count(value) >= 3: + return True + return False + + def is_four_of_a_kind(self): + faces = self.faces() + for value in set(faces): + if faces.count(value) >= 4: + return True + return False + + dice = FiveDice() successes = 0 +successes_three = 0 +successes_four = 0 + trials = 1000000 for trial in tqdm(range(trials)): dice.roll() if dice.all_ones(): successes += 1 + if dice.is_three_of_a_kind(): + successes_three += 1 + if dice.is_four_of_a_kind(): + successes_four += 1 print(successes/trials) +print("Odds of three-of-a-kind:", successes_three / trials) +print("Odds of four-of-a-kind:", successes_four / trials)