Completed checkpoint one by adding two new methods

You could model vehicles in the world using classes. Car, truck,
motorcycle, boat, plane, helicopter etc. could be classes.
2024 toyota prius, 2022 ford bronco, and 2023 Cadillac Escalade
would all be instances of of the car class.
This commit is contained in:
root 2024-02-04 18:03:09 -05:00
parent 2bc5aa0e05
commit 9e7cde5211
3 changed files with 40 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -12,22 +12,59 @@ class FiveDice:
def faces(self):
return [die.face for die in self.dice]
def all_ones(self):
for face in self.faces():
if face != 1:
return False
return True
def is_three_of_a_kind(self):
of_each_counter={1:0, 2:0, 3:0, 4:0, 5:0, 6:0}
for face in self.faces():
of_each_counter[face]=of_each_counter[face]+1
for num_of in of_each_counter.values():
if num_of>=3:
return True
return False
def is_four_of_a_kind(self):
of_each_counter={1:0, 2:0, 3:0, 4:0, 5:0, 6:0}
for face in self.faces():
of_each_counter[face]=of_each_counter[face]+1
for num_of in of_each_counter.values():
if num_of>=4:
return True
return False
dice = FiveDice()
successes = 0
trials = 1000000
for trial in tqdm(range(trials)):
dice.roll()
if dice.all_ones():
successes += 1
print('all ones odds')
print(successes/trials)
print('_'*80)
successes = 0
trials = 1000000
for trial in tqdm(range(trials)):
dice.roll()
if dice.is_three_of_a_kind():
successes += 1
print('three of a kind odds')
print(successes/trials)
print('_'*80)
successes = 0
trials = 1000000
for trial in tqdm(range(trials)):
dice.roll()
if dice.is_four_of_a_kind():
successes += 1
print('four of a kind odds')
print(successes/trials)
print('_'*80)