generated from mwc/lab_dice
I tried to finish checkpoint 1 but no matter what I did it kept giving me 100%.
Checkpoint 1: You could use classes when coding something that uses multiple functions. For example, any game with multiple players could be made with classes.
This commit is contained in:
@@ -19,6 +19,36 @@ class FiveDice:
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_three_of_a_kind(self):
|
||||
for face in self.faces():
|
||||
if face != face != face:
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_four_of_a_kind(self):
|
||||
for face in self.faces():
|
||||
if face != face != face != face:
|
||||
return False
|
||||
return True
|
||||
|
||||
dice = FiveDice()
|
||||
successes = 0
|
||||
trials = 1000000
|
||||
for trial in tqdm(range(trials)):
|
||||
dice.roll()
|
||||
if dice.is_three_of_a_kind():
|
||||
successes += 1
|
||||
print(successes/trials)
|
||||
|
||||
dice = FiveDice()
|
||||
successes = 0
|
||||
trials = 1000000
|
||||
for trial in tqdm(range(trials)):
|
||||
dice.roll()
|
||||
if dice.is_four_of_a_kind():
|
||||
successes += 1
|
||||
print(successes/trials)
|
||||
|
||||
dice = FiveDice()
|
||||
successes = 0
|
||||
trials = 1000000
|
||||
@@ -26,7 +56,6 @@ for trial in tqdm(range(trials)):
|
||||
dice.roll()
|
||||
if dice.all_ones():
|
||||
successes += 1
|
||||
|
||||
print(successes/trials)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user