Files
lab_dice/dice_stats.py
caglazir 773aebc443 I edited the dice code to include 3 & 4 of a kind.
Checkpoint 1: I am not familiar with classes at all so I am still
a little unsure of what I could implement this on. Maybe for things that need
to run multiple times until it corresponds to a certain value... The first
thing I can think of is hacking! Like in the movies the hackers run bunch of
passwords until they find the right one, lol! Since we're also in the game unit,
I remember there was these dressing up games that would score your outfit for certain
events. I wonder if they utilized a similar thing where they went through various combinations
that the players made and scored if they were matching (like three of a kind, etc.).
2025-11-16 20:37:25 -05:00

48 lines
955 B
Python

from die import Die
from tqdm import tqdm
class FiveDice:
def __init__(self):
self.dice = [Die() for number in range(5)]
def roll(self):
for die in self.dice:
die.roll()
return self.faces()
def faces(self):
return [die.face for die in self.dice]
def all_ones(self):
for face in self.faces():
if face != 1:
return False
return True
def is_three_of_a_kind(self):
for face in self.faces():
if self.faces.count(face) >= 3:
return True
return False
def is_four_of_a_kind(self):
for face in self.faces():
if self.faces.count(face) >= 4:
return True
return False
dice = FiveDice()
successes = 0
trials = 1000000
for trial in tqdm(range(trials)):
dice.roll()
if dice.all_ones():
successes += 1
print(successes/trials)