From 94c94357cae1d7d7b4bf69954f3f0ef63a081e40 Mon Sep 17 00:00:00 2001 From: niciahrymer-hillian Date: Thu, 16 Apr 2026 15:46:38 -0400 Subject: [PATCH 1/3] initial commit to save progress --- python/__pycache__/bins.cpython-314.pyc | Bin 0 -> 1484 bytes python/__pycache__/dice.cpython-314.pyc | Bin 0 -> 934 bytes python/__pycache__/simulation.cpython-314.pyc | Bin 0 -> 1538 bytes python/app.py | 15 +++++++++------ python/bins.py | 13 +++++++++++++ python/dice.py | 11 +++++++++++ python/simulation.py | 18 ++++++++++++++++++ 7 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 python/__pycache__/bins.cpython-314.pyc create mode 100644 python/__pycache__/dice.cpython-314.pyc create mode 100644 python/__pycache__/simulation.cpython-314.pyc create mode 100644 python/bins.py create mode 100644 python/dice.py create mode 100644 python/simulation.py diff --git a/python/__pycache__/bins.cpython-314.pyc b/python/__pycache__/bins.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c916ed5c7f137df01b7a7ed22395bbc3a9b66abe GIT binary patch literal 1484 zcmc&z&rcIU6n?wgLZMq)exry4n=~So0zpM-OhpfBl#oW?f=rfW(bZ)Ovr{8CZfar_ z6BF^IoRFJF6aN9vhD!zaMm*^W=>dA&2&_SDgnpy#D@7v z0{BLY((o0H{9!cap&r^G4ULeNdgVeyKw6GMyP}seXvQku$oJr+Vcty;QW}IjE(xUp zGML{8!k3m2{b>cUEbSBJBOn54KUOPqeFLWL=t{8;O=RO2$X`Wc9>$?l8f}Yvol_WK zT#6SA599uw#R%Ac7NZfn)E#z#|B}B`Y;Z+(eG~Xkw|v^P**(o_S6rWCSW`TJVf1SE z$?H%Xu~^JKnHY8q?j&qezdM&0;+Z>!E}XZ&#b(WUIqSJyf59{>}3l|s9J5xw`I$zQ+~ojYprTdE5Yck#VwtPUo@l z1C4nYfg$q#HEu{*xnJ%(2QZ1$9QnttF*=eru!^r_@65eLzIL=?V(#kcQSW`PtGPNtGcKlR8y&&-_EVjR1pS|Dw z7rl;`^csgK-GzO$K3K2aT1D{{;tP^E-9}zbP>ZmK{qkEzfp^v8y||)h>kJ?q$T;e- z5sqvsP}lV0?6b3r!^>k!W4V^@Ty4*)+VeFW@wnzB;b40Oy)#>zHt?NQGB%x=%vxlt zjLl{>s~8D0Hf3^0Sf*{*8OFGZ$-JJR3Bj#r%n_O}b*2fy&55iq94u1Jm~Lr~GimBV zH!O>>cF7Ixa$*`?&XjlUIK3(l$mbkF`1JsfyCuv1)~$f-@7@k5{_0IYC>((j29Zpf jSD@hYE^r`OILLW^3`1VIFdCbRBuU${DpltJ!AtlJV$cu7 literal 0 HcmV?d00001 diff --git a/python/__pycache__/dice.cpython-314.pyc b/python/__pycache__/dice.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d9267c3199f9463a4f2ccee1c7817971cd0f82ca GIT binary patch literal 934 zcmbVKzi-n}5WZ(SjvF-%Ka^HfAgC%;N&~fsIwHit08$lImgod|avfJVIClHq%a97B zY=AnzSj52GKL)7_5_*CGF?Flzp^V(wNfkPB!{_ha-MjnVottyj3ZT7ne??#M``IxK-_EP!XO8%35fJZl*mr4u?HFi@b z_*nA=DCU7OI;Jw`A;k_0pe(AaN}h>mdzLD1fpWYOR=2hFI10jGQisZsN)y1z7LknL z`9-Y5I`%}}GD~mXUQ<$k>pv?_uOYP6w*zi;MLIG6lpIElys@naKqnrcZcd_ znz&s&uk8+XiO79jq4-+PNkTStO9yX`otqhY;D59V2QTJI1#PF0DQ1xt z&0AB=TV=|v5nMs|ryadDAI%1m5p2Qc#c!} zu5jK@yMvhcEa!UzKORSFobN>gj|1~+isZJ urk_9U3u{t9ED)mw6>D@J6c2kS?x2raN*d&;$r$?yi|3ZZni(MEcm4ta^S6fp literal 0 HcmV?d00001 diff --git a/python/__pycache__/simulation.cpython-314.pyc b/python/__pycache__/simulation.cpython-314.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3e59bc4480ec86e567d844ebd975db7232965fd4 GIT binary patch literal 1538 zcmZux&u<%55T5Pnp5mgec(gWhuTU8&*k(u?bouH1adGp@9nc44~dA^WIrvT+q zXfNpKhodW(=SX-XK>^K`82T zf>tf-LB?x0H*L=REp{K#1li$U`a;-(Q)HlT5@apVh3#(fQ9R;Av><1xR0=+0Z+e&k#`5aI;=(Qq?lM1BYzfF zJ_cwhL;e<{D=oFIu8qX^hwH$vVdmuUJhs-}h^^sT*W!9JaBCT06sDmD*bk*zP6P&T zcn|E5S57bjojSlNPmp#zi`z}xlMFji*11Wi3JdhGYYA?PwkrjNm5Rk8Pm?>t+a4QI z9!#BL`K&AKJA#I%6cL*aud;~rVDc2NXFSA+_y|>>*6r?lKfjHPnz_fHcelIN{`me^zpeke zel)jqFt_yQ_Fr?KJb8cl$=KyX^GZ*HvFVV~vKD^R@X=Mvqx5vVM$^WplVYst-*3BQ zn~ZI@8*b!zld&y_3+XzZ?fH!H41NipBsGmH$TKD+{?k~jAtiS<+tL=8B*&QLHiW>z zl9uhdjNxBh`qUwY(W|)@4jE5SK2p>xF@@^i?-B1yRWph&Q@Sz#%2bW3F91~tC%juN z8+}mJbUs0f!b9I5(7zXsaPmqY+^76J`l+nQqk5q!it-Hd_OB6yj literal 0 HcmV?d00001 diff --git a/python/app.py b/python/app.py index e71e427..8f6f51f 100644 --- a/python/app.py +++ b/python/app.py @@ -1,9 +1,12 @@ -class Bin: - pass +from simulation import Simulation -class Dice: - pass -class Simulation: - pass +def main(): + sim = Simulation(2, 10000) + sim.run_simulation() + sim.print_results() +# make interactive menu using similar code to Microbank + +if __name__ == "__main__": + main() diff --git a/python/bins.py b/python/bins.py new file mode 100644 index 0000000..60f58e1 --- /dev/null +++ b/python/bins.py @@ -0,0 +1,13 @@ +class Bins: + def __init__(self, min_val, max_val): + self.bins = [0] * (max_val - min_val + 1) + self.min_val = min_val + + def increment_bin(self, value): + if self.min_val <= value < self.min_val + len(self.bins): + self.bins[value - self.min_val] += 1 + + def get_bin(self, value): + if self.min_val <= value < self.min_val + len(self.bins): + return self.bins[value - self.min_val] + return 0 diff --git a/python/dice.py b/python/dice.py new file mode 100644 index 0000000..aa27cac --- /dev/null +++ b/python/dice.py @@ -0,0 +1,11 @@ +from random import randint + +class Dice: + def dice1(self): + return randint(1, 6) + + def dice2(self): + return randint(1, 6) + + def toss(self): + return self.dice1() + self.dice2() diff --git a/python/simulation.py b/python/simulation.py new file mode 100644 index 0000000..9c5e192 --- /dev/null +++ b/python/simulation.py @@ -0,0 +1,18 @@ +from bins import Bins +from dice import Dice + +class Simulation: + def __init__(self, number_of_dice, number_of_tosses): + self.number_of_dice = number_of_dice + self.number_of_tosses = number_of_tosses + self.bins = Bins(2, 12) + + def run_simulation(self): + for _ in range(self.number_of_tosses): + dice = Dice() + result = dice.toss() + self.bins.increment_bin(result) + + def print_results(self): + for i in range(2, 13): + print(f"Number of {i}s: {self.bins.get_bin(i)}") From e0da47aaf62861d51a6fa35ef5050a1049c34121 Mon Sep 17 00:00:00 2001 From: niciahrymer-hillian Date: Thu, 16 Apr 2026 17:07:57 -0400 Subject: [PATCH 2/3] stuck, will get back to it soon --- python/__pycache__/simulation.cpython-314.pyc | Bin 1538 -> 3328 bytes python/app.py | 109 ++++++++++++++++-- python/bins.py | 13 --- python/dice.py | 11 -- python/roll_log.txt | 3 + python/simulation.py | 18 --- 6 files changed, 105 insertions(+), 49 deletions(-) delete mode 100644 python/bins.py delete mode 100644 python/dice.py create mode 100644 python/roll_log.txt delete mode 100644 python/simulation.py diff --git a/python/__pycache__/simulation.cpython-314.pyc b/python/__pycache__/simulation.cpython-314.pyc index 3e59bc4480ec86e567d844ebd975db7232965fd4..1ebe60fee09817678c9d7ff0be8577c338ba46f5 100644 GIT binary patch literal 3328 zcmb6bO>Em#__H0mPUfyn(l(`A7mv0XX}c7$X^3@9+ZfZzMwNM?WvI+bQx6P|ojp51 zDOK#$l3l&W^BWIfqL^JM0IAOMntO z%vLy@kiz#sTKJ7F(~KKBrJFYWp4JOmp+ZxEOm(q!94C1^W;yO0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vTa-216$)0_bZnABQH@nnqW7vLh(vvYs6*_doGyY{*knWD_ycKRGXk+T zEQ8VboZuDF|CKW~q}al%^RF)LUzPUy^WN*}FVgE>11ntvH&5Q{%B)F4wCG-BHbn?a z3r+J)i&$op8{#fnc$Z^+t73{SBJ+{OW2>U<&xfl-bpObz*hTlndGT80&qw>Ab2+6%ZSuJBmrY~!W8ri&+-dGOeSo`@Vh~~_rO7wwB1hA^XfJ5yiyHQV z5mhZ(Q)PqBB~`sz&Kp%si>hAHiH+W7YNn;CWH%K9Gy-48ohzVo5T@-O}&#`*XrAn?+$$2E$M<2@8}F}6;4s77eOdB|H(A@tfR@mS@> f$H^(g(;L_{&unrG!#sd?{QV&eGVv`y;IaJ;xy5zH delta 717 zcmYjN&ubGw6n^_-Hb1%vP1CeZTjOe=b!ke27Aq~4R;5@9p+*Q4V@g_AS!gzKc5|r* zgBR0_8U{4rMQ@%w`%icXlr}68@#sN_&7mHBvyH{a@bTuoZ@xG0tBt=JgEF!t0Do_#(Vf-`VnLl3 zxeh=MENq-bRzSY^Q)IV=k1GUg_5?x=+KJSmf1<6W5B(Q9!(+`z^A_8v%dY}G{%%*` z*pKr;pIAsvlN$gPffdCl5p&|Ek2Od%)Mr+t9Blg8Jztb{$?$V&zAtkTHWmQ_kbo@U zcZ7_txP%t1CkExKQ$E3!ow9Ay0iK3TYnK`&!*aHFOiP!k%B#Y*D?c)K4OgLtUEOnR z{%lIqG|K0@VOq7eZL?I}D>`P`a^vi?9AD-7_7Xx3I+2k#&hcofHJUn#%+^;s(NT82 zey1IazuRhTu?O|FwmSHF{b2oAO}5nJhqWVhrsre7 Date: Thu, 16 Apr 2026 18:02:20 -0400 Subject: [PATCH 3/3] It works now, changed the wording on the printing results area and the bin structure --- python/app.py | 122 ++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 64 deletions(-) diff --git a/python/app.py b/python/app.py index 8cb21a7..ec174fe 100644 --- a/python/app.py +++ b/python/app.py @@ -1,11 +1,6 @@ import random - - -def append_to_log(result): - """Append the result to a log file for record-keeping.""" - with open('roll_log.txt', 'a') as log_file: - log_file.write(f"{result}\n") +import unittest class Bins: @@ -24,25 +19,27 @@ def get_bin(self, value): class Dice: - def roll(self): - return random.randint(1, 6) - - -class Simulation: - def __init__(self, number_of_dice, number_of_tosses): -self.min_sum = number_of_dice - + def __init__(self, number_of_dice): self.number_of_dice = number_of_dice - self.number_of_tosses = number_of_tosses - self.bins = Bins(number_of_dice, number_of_dice * 6) def toss(self): - rolls = [] + return [random.randint(1, 6) for _ in range(self.number_of_dice)] + + def toss_and_sum(self): + return sum(self.toss()) - for _ in range(self.number_of_dice): - die = Dice() - rolls.append(die.roll()) +class Simulation: + def __init__(self, numberOfDies, numberOfTosses): + self.number_of_dice = numberOfDies + self.number_of_tosses = numberOfTosses + self.min_sum = numberOfDies + self.max_sum = numberOfDies * 6 + self.dice = Dice(numberOfDies) + self.bins = Bins(self.min_sum, self.max_sum) + + def toss(self): + rolls = self.dice.toss() result = sum(rolls) self.bins.increment_bin(result) return rolls, result @@ -52,56 +49,53 @@ def run_simulation(self): self.toss() def print_results(self): - """Print the simulation results.""" + print('***') + print(f'Simulation of {self.number_of_dice} dice tossed for {self.number_of_tosses} times.') print('***') print() + for sum_value in range(self.min_sum, self.max_sum + 1): - count = self.results.get_bin(sum_value) - percentage = count / self.number_of_tosses -# Create histogram bar: asterisks = floor(percentage * 100) - histogram_bars = int((count / self.number_of_tosses) * 100) + count = self.bins.get_bin(sum_value) + percentage = count / self.number_of_tosses + histogram_bars = '*' * int(percentage * 100) + print(f'{sum_value:2d} : {count:8d}: {percentage:.2f} {histogram_bars}') + + +class TestDice(unittest.TestCase): + def test_toss_returns_correct_number_of_rolls(self): + dice = Dice(2) + rolls = dice.toss() + + self.assertEqual(len(rolls), 2) + self.assertTrue(all(1 <= roll <= 6 for roll in rolls)) + + def test_toss_and_sum_range(self): + dice = Dice(2) + total = dice.toss_and_sum() + + self.assertTrue(2 <= total <= 12) + + +class TestBins(unittest.TestCase): + def test_increment_bin(self): + results = Bins(2, 12) + results.increment_bin(10) + + self.assertEqual(results.get_bin(10), 1) + + def test_get_bin_out_of_range(self): + results = Bins(2, 12) + + self.assertEqual(results.get_bin(1), 0) - print(f"{sum_value:2d} : {count:8d}: {percentage:.2f} {'*' * histogram_bars}") - print(f'Simulation of {self.number_of_dice} dice tossed for {self.number_of_tosses} times.') - print('***') def main(): - sim = Simulation(2, 10000) - sim.run_simulation() - sim.print_results() - - open('roll_log.txt', 'a').close() - - while True: - print('\nWelcome to Nickys Dice Game!') - print('Toss') - print('Check Roll Log') - print('Exit') - choice = input('Choose an option to start your game: ').strip().lower() - - if choice == 'toss': - print('Tossing the dice...') - rolls, result = sim.toss() - print('You rolled: ' + ', '.join(str(roll) for roll in rolls)) - append_to_log(result) - print(f'You rolled a total of: {result}') - - elif choice == 'check roll log': - try: - with open('roll_log.txt', 'r') as log_file: - print('Roll Log:') - for line in log_file: - print(line.strip()) - except FileNotFoundError: - print('No roll log found yet.') - - elif choice == 'exit': - print('Thank you for using Nickys Dice Game. Goodbye!') - break - - else: - print('Please choose a valid option.') + sim = Simulation(2, 10000) + sim.run_simulation() + sim.print_results() if __name__ == '__main__': - main() \ No newline at end of file + main() + +