generated from mwc/lab_dice
Completed Checkpoint 1.
1) I think making a game, you could simulate a character class in an RPG! Hair color, wieght, special abilities, each character would be a different object in the character class.
This commit is contained in:
parent
019f6519c6
commit
80535dd986
Binary file not shown.
|
@ -1,5 +1,6 @@
|
||||||
from die import Die
|
from die import Die
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
class FiveDice:
|
class FiveDice:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -19,6 +20,21 @@ class FiveDice:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def is_three_of_a_kind(self):
|
||||||
|
count = Counter(self.faces())
|
||||||
|
for face_count in count.values():
|
||||||
|
if face_count == 3:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def is_four_of_a_kind(self):
|
||||||
|
count = Counter(self.faces())
|
||||||
|
for face_count in count.values():
|
||||||
|
if face_count == 4:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
dice = FiveDice()
|
dice = FiveDice()
|
||||||
successes = 0
|
successes = 0
|
||||||
trials = 1000000
|
trials = 1000000
|
||||||
|
@ -28,6 +44,9 @@ for trial in tqdm(range(trials)):
|
||||||
successes += 1
|
successes += 1
|
||||||
|
|
||||||
print(successes/trials)
|
print(successes/trials)
|
||||||
|
#print(f"dice rolls: {dice.faces()}")
|
||||||
|
print(dice.faces())
|
||||||
|
print(dice.is_three_of_a_kind())
|
||||||
|
print(dice.is_four_of_a_kind())
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue