From 6263f6acddf39f031fc91650042eeba31e622136 Mon Sep 17 00:00:00 2001 From: Rebecca Hankey Date: Thu, 21 Nov 2024 18:55:50 -0500 Subject: [PATCH] I created two new methods for the calculation of running the same simulation but for instances where three of a kind are rolled with five dice and four of a kind are rolled with five dice. Classes are a really useful way to run these high probability situations. It might be fun to run something like the odds of winning certian bets or the odds of your lottery numbers being the correct ones. Is that legal? Feels illegal... Anyway, it would also be interesting to combine these simulations with data from other labs that we have done in class. For example, the weather lab. Could you create a simluation that has a thing (like the die or a weather event) and an environment in which to run that thing that has certian rules based off of data? So, for example, could you run a simulation about the liklihood of a weather event hitting your property? Or would that be more data science (like unit 2)? --- dice_stats.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..b0e7edb 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -19,6 +19,22 @@ class FiveDice: return False return True + def is_three_of_a_kind(self): + faces = self.faces() + for self in self.faces(): + for count in range (1, 7): + if faces.count(count) >= 3: + return True + return False + + def is_four_of_a_kind(self): + faces = self.faces() + for self in self.faces(): + for count in range(1, 7): + if faces.count(count) >= 4: + return True + return False + dice = FiveDice() successes = 0 trials = 1000000 @@ -26,6 +42,21 @@ for trial in tqdm(range(trials)): dice.roll() if dice.all_ones(): successes += 1 +print(successes/trials) + +successes_three_of_a_kind = 0 +for trial in tqdm(range(trials)): + dice.roll() + if dice.is_three_of_a_kind(): + successes_three_of_a_kind += 1 +print("Odds of three of a kind", successes_three_of_a_kind / trials) + +successes_four_of_a_kind = 0 +for trial in tqdm(range(trials)): + dice.roll() + if dice.is_four_of_a_kind(): + successes_four_of_a_kind += 1 +print("Odds of four of a kind", successes_four_of_a_kind / trials) print(successes/trials)