generated from mwc/lab_dice
I knew I had to see how many of the dice were the same but I unsure how to do it so i did some research on the internet to help me solve this one.
A problem you could solve with classes in coding could be a algebara problem that requires multiple steps. I have trouble thinking of real life situtations
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from die import Die
|
||||
from tqdm import tqdm
|
||||
from collections import Counter
|
||||
|
||||
class FiveDice:
|
||||
def __init__(self):
|
||||
@@ -19,6 +20,22 @@ class FiveDice:
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_three_of_a_kind(self):
|
||||
counts = Counter(self.dice)
|
||||
for count in counts.value():
|
||||
if count >= 3:
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_four_of_a_kind(self):
|
||||
counts = Counter(self.dice)
|
||||
for count in counts.value():
|
||||
if count >= 4:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
dice = FiveDice()
|
||||
successes = 0
|
||||
trials = 1000000
|
||||
|
||||
Reference in New Issue
Block a user