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 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):
|
||||||
@@ -18,6 +19,22 @@ class FiveDice:
|
|||||||
if face != 1:
|
if face != 1:
|
||||||
return False
|
return False
|
||||||
return True
|
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()
|
dice = FiveDice()
|
||||||
successes = 0
|
successes = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user