From b1d374d1d56ecf9500dc54fecbe0b74e1b763f3d Mon Sep 17 00:00:00 2001 From: ilmabura Date: Mon, 17 Nov 2025 23:00:52 -0500 Subject: [PATCH] completed checkpoint 1 From what i've understood, classes are supposed to make it easier to call on a group of objects/methods all at once. I think a good simulation to use classes for would be an epidemic. Person would be one class and the methods would be susceptible, infected, recovered. Virus and Interactions would be two more classes. --- dice_stats.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..64d8087 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -18,6 +18,16 @@ class FiveDice: if face != 1: return False return True + def is_three_of_a_kind(self): + count={} + for face in self.faces(): + count[face]=count.get(face, 0)+1 + return any(count >= 3 for count in count.values()) + def is_four_of_a_kind(self): + count={} + for face in self.faces(): + count[face]=count.get(face, 0)+1 + return any(count >= 4 for count in count.values()) dice = FiveDice() successes = 0 @@ -26,8 +36,24 @@ for trial in tqdm(range(trials)): dice.roll() if dice.all_ones(): successes += 1 +print("all ones", successes/trials) -print(successes/trials) - +dice = FiveDice() +successes = 0 +trials = 1000000 +for trial in tqdm(range(trials)): + dice.roll() + if dice.is_three_of_a_kind(): + successes += 1 +print("three of a kind", successes/trials) + +dice = FiveDice() +successes = 0 +trials = 1000000 +for trial in tqdm(range(trials)): + dice.roll() + if dice.is_four_of_a_kind(): + successes += 1 +print("four of a kind", successes/trials)