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)?
This commit is contained in:
Rebecca Hankey 2024-11-21 18:55:50 -05:00
parent f9a5e63425
commit 6263f6acdd
1 changed files with 31 additions and 0 deletions

View File

@ -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)