-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsimulation.py
More file actions
29 lines (20 loc) · 863 Bytes
/
simulation.py
File metadata and controls
29 lines (20 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from src.main.python.bins import Bins
from src.main.python.dice import Dice
class Simulation:
def __init__(self, numberdice, numberrolls):
self.numberOfDice = numberdice
self.numberOfRolls = numberrolls
self.dice = Dice(self.numberOfDice)
self.bins = Bins(self.numberOfDice)
def runSimulation(self):
self.bins.create_bin()
for i in range(self.numberOfRolls):
dicesum = self.dice.tossAndSum()
self.bins.increment_bin(dicesum)
self.printStars(self.bins.list)
def printStars(self, list):
for x in list:
stars = ""
for y in range(1, int(100*x/self.numberOfRolls)):
stars = stars + "*"
print("sum: %-5s times: %-7s percent: %-9s : %s" % (list.index(x) + self.numberOfDice, x, x/self.numberOfRolls, stars))