From 9e7cde5211166ba72732478c6f399518f44ab096 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 4 Feb 2024 18:03:09 -0500 Subject: [PATCH] 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. --- __pycache__/dice_stats.cpython-310.pyc | Bin 0 -> 1403 bytes __pycache__/die.cpython-310.pyc | Bin 0 -> 718 bytes dice_stats.py | 43 +++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 __pycache__/dice_stats.cpython-310.pyc create mode 100644 __pycache__/die.cpython-310.pyc diff --git a/__pycache__/dice_stats.cpython-310.pyc b/__pycache__/dice_stats.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..13353376d08b926550aef9aa036d729d6b24c0a4 GIT binary patch literal 1403 zcma)6OK;Oa5T0E>;-pENmRBV>AS4cvPy*rrhpMWeDz{w9$x>yx-feN~N3(XQh*Am3 z{R8}i=Gb4s|L~PlkBA!=m{~V%QgXo2j%U~N_~x70q^(v1@HzPTT^@0OAGDc$4BTwt z$`TX;1dAYME@Pzgh{xRJ3_gG`gn16aEVye(qX5?w;9A0RZOLU#+661vHta3Cjx;ao z6JUVv#spMXTEc#Vwu7f~Nm|l=3nN&dIaWzk z6l@G0X2A$%f6kGhkmD{nuAw-DG3;4qEQbQV@d4k3OHgFh;U(|BEbU|%?@Og@JksL# z+n!3(yche&VRGo5hWRHiNQLahr@^bp3ZK5*uxUwoxmhzKBS(+3Yi8nJD9o(W*b+js- zX&~~+D9t(>t^Si{Av2oNC+ISUBfx>M&)Aq^r{8)Nk+3>tL6~l=1rsoZYepG!?tCWh`s{yD- zq}>v#HJVCA!)W5tnH_MLV>njR(C6XSyA@Cm@oT@+ta?H`D6-cE)v(pGVSsa%$*i<< y72*|9L~Uv5O$CDTm)402lY9}3(%Go$*d*TcpGOmUSmySc$xPNpM(D@Cw)tPN?GBFs literal 0 HcmV?d00001 diff --git a/__pycache__/die.cpython-310.pyc b/__pycache__/die.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d58064bcdbf6384fc5966491672fbd7656f25383 GIT binary patch literal 718 zcmZ`%y>8n;3?}a+S#@O;$XcLN7cCKju0;``1-g0h=7ms2IZ>;h_9P>ykdA}RJT~nL1gp$zI=%QztlMuE6$~8|4Ix4V+{?i5#b}S zVS5K`_hxN4SV0;dB?nUUGncnqwL_u)sTgrCMf=xcN?0RoT=I(toFGCZ?MDR1F`$ Oo$%jja}(Y0%=`s@+=OZX literal 0 HcmV?d00001 diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..e77caa3 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -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)