generated from mwc/lab_dice
This was intersting. The probablity with dice is a good tool to use in class, but sometimes it's not so intuitive for some students espeically when there are multiple dice involved. This activity could encourage students to discuss and changing the code or writing a new code is a good way to simulate each probablity case. For example, three_of_a_kind and four_of_a_kind, how similar they are and how different they are is good way to start a conversation, then how we can change the code can be easily done once students fully understand how to calculate probablity.
This commit is contained in:
parent
dfcd109947
commit
b7f1ec19bf
|
@ -18,13 +18,30 @@ class FiveDice:
|
|||
if face != 1:
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_three_of_a_kind(self):
|
||||
if sum([d.face == self.dice[0].face for d in self.dice]) == 3:
|
||||
return True
|
||||
if sum([d.face == self.dice[1].face for d in self.dice]) == 3:
|
||||
return True
|
||||
if sum([d.face == self.dice[2].face for d in self.dice]) == 3:
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_four_of_a_kind(self):
|
||||
if sum([d.face == self.dice[0].face for d in self.dice]) == 4:
|
||||
return True
|
||||
if sum([d.face == self.dice[1].face for d in self.dice]) == 4:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
dice = FiveDice()
|
||||
successes = 0
|
||||
trials = 1000000
|
||||
for trial in tqdm(range(trials)):
|
||||
dice.roll()
|
||||
if dice.all_ones():
|
||||
if dice.is_four_of_a_kind():
|
||||
successes += 1
|
||||
|
||||
print(successes/trials)
|
||||
|
|
Loading…
Reference in New Issue