generated from mwc/lab_dice
Checkpoint 1
A class could be used to create an object, such as a molecule in chemistry. In the class definition, would be functions that could describe how general molecules behave, look, etc. and then when the class is called later, certain attributes such as the type of molecule could be defined. If I am thinking about a class correctly, it could be used to describe the behavior of a molecule for simulation, but then the actual individual characteristics of the molecule could be called later.
This commit is contained in:
parent
983a9d5957
commit
e798485b0d
|
@ -11,23 +11,60 @@ class FiveDice:
|
|||
return self.faces()
|
||||
|
||||
def faces(self):
|
||||
return [die.face for die in self.dice]
|
||||
return [die.face for die in self.dice] #this is a list of all die faces
|
||||
|
||||
def all_ones(self):
|
||||
for face in self.faces():
|
||||
if face != 1:
|
||||
return False
|
||||
return True
|
||||
|
||||
dice = FiveDice()
|
||||
successes = 0
|
||||
trials = 1000000
|
||||
for trial in tqdm(range(trials)):
|
||||
dice.roll()
|
||||
if dice.all_ones():
|
||||
successes += 1
|
||||
|
||||
print(successes/trials)
|
||||
|
||||
def is_three_of_a_kind(self):
|
||||
for value in range(6):
|
||||
instances = self.faces().count(value)
|
||||
if instances >= 3:
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_four_of_a_kind(self):
|
||||
for value in range(6):
|
||||
instances = self.faces().count(value)
|
||||
if instances >= 4:
|
||||
return True
|
||||
return False
|
||||
|
||||
dice = FiveDice()
|
||||
trials = 1000000
|
||||
|
||||
|
||||
def check_all_ones():
|
||||
successes = 0
|
||||
for trial in tqdm(range(trials)):
|
||||
dice.roll()
|
||||
if dice.all_ones():
|
||||
successes += 1
|
||||
print("All ones is")
|
||||
print(successes/trials)
|
||||
|
||||
def check_3_of_a_kind():
|
||||
successes=0
|
||||
for trial in tqdm(range(trials)):
|
||||
dice.roll()
|
||||
if dice.is_three_of_a_kind():
|
||||
successes += 1
|
||||
print("Three of a Kind is")
|
||||
print(successes/trials)
|
||||
|
||||
def check_4_of_a_kind():
|
||||
successes=0
|
||||
for trial in tqdm(range(trials)):
|
||||
dice.roll()
|
||||
if dice.is_four_of_a_kind():
|
||||
successes += 1
|
||||
print("Four of a Kind is")
|
||||
print(successes/trials)
|
||||
|
||||
check_all_ones()
|
||||
check_3_of_a_kind()
|
||||
check_4_of_a_kind()
|
||||
|
||||
|
|
Loading…
Reference in New Issue