From fef914e39c6593c3b0702611b0f3fe7b41a1e8e4 Mon Sep 17 00:00:00 2001 From: Asaw89 Date: Sun, 9 Nov 2025 13:56:33 -0500 Subject: [PATCH] added results --- python/AlanResults.md | 11 +++++++++ python/Bin_Example.py | 20 +++++++++++++++ python/Dice_Example.py | 14 +++++++++++ python/app.py | 56 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 python/AlanResults.md create mode 100644 python/Bin_Example.py create mode 100644 python/Dice_Example.py diff --git a/python/AlanResults.md b/python/AlanResults.md new file mode 100644 index 0000000..1081b42 --- /dev/null +++ b/python/AlanResults.md @@ -0,0 +1,11 @@ + 2: 27761: 0.03 ** + 3: 55600: 0.06 ***** + 4: 83417: 0.08 ******** + 5: 111270: 0.11 *********** + 6: 138257: 0.14 ************* + 7: 166620: 0.17 **************** + 8: 139601: 0.14 ************* + 9: 110903: 0.11 *********** +10: 83417: 0.08 ******** +11: 55339: 0.06 ***** +12: 27815: 0.03 ** \ No newline at end of file diff --git a/python/Bin_Example.py b/python/Bin_Example.py new file mode 100644 index 0000000..fe32ac7 --- /dev/null +++ b/python/Bin_Example.py @@ -0,0 +1,20 @@ +from Dice_Example import Dice + +class Bins: + def __init__(self, min_value, max_value): + self.bins = [] + for i in range(min_value, max_value + 1): + self.bins[i] = 0 + + def get_bin(self, bin_number): + return self.bins[bin_number] + + def increment_bin(self, bin_number): + self.bins[bin_number] += 1 + + +if __name__ == "__main__": + results = Bins(2, 12) + results.increment_bin(10) + number_of_10s = results.get_bin(10) + print(f"Number of 10s: {number_of_10s}") diff --git a/python/Dice_Example.py b/python/Dice_Example.py new file mode 100644 index 0000000..91d94af --- /dev/null +++ b/python/Dice_Example.py @@ -0,0 +1,14 @@ +import random + +class Dice: + def roll(self): + return random.randint(1, 6) + + def toss_and_sum(self): + n = int(input("How many dice? ")) + total = sum(self.roll() for i in range(n)) + return total + +dice = Dice() +toss = dice.toss_and_sum() +print(f"You rolled {toss}") \ No newline at end of file diff --git a/python/app.py b/python/app.py index e71e427..efcd320 100644 --- a/python/app.py +++ b/python/app.py @@ -1,9 +1,59 @@ +import random + class Bin: - pass + def __init__(self, min_value, max_value): + self.bins = [] + for i in range(min_value, max_value + 1): + self.bins.append(0) + + def get_bin(self, bin_number): + return self.bins[bin_number-2] + + def increment_bin(self, bin_number): + self.bins[bin_number-2] += 1 + class Dice: - pass + def __init__(self,numberOfDice, numberOfSides): + self.numberOfDice = numberOfDice + self.numberOfSides = numberOfSides + + + def roll(self): + return random.randint(1, self.numberOfSides) + + def toss_and_sum(self, numberOfDice): + total = sum(self.roll() for i in range(numberOfDice)) + return total + class Simulation: - pass + def __init__ (self, numberOfDies, numberOfTosses, numberOfSides): + self.numberOfDies = numberOfDies + self.numberOfTosses = numberOfTosses + self.numberOfSides = numberOfSides + self.dice = Dice(numberOfDies, numberOfSides) + self.results = Bin(numberOfDies, numberOfDies* numberOfSides) + + def run_simulation(self): + for i in range(self.numberOfTosses): + toss = self.dice.toss_and_sum(self.numberOfDies) + self.results.increment_bin(toss) + + def print_results(self): + for i in range(self.numberOfDies,self.numberOfDies*self.numberOfSides+1): + pct=self.results.get_bin(i)/self.numberOfTosses + print(f"{i:2}: {self.results.get_bin(i):8}: {pct:.2f} ",end="") + for j in range(0,(int)(pct*100)): + print("*",end="") + print("") + + + + + +if __name__ == "__main__": + sim = Simulation(2, 1000000,6) + sim.run_simulation() + sim.print_results() \ No newline at end of file