-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprobabilityCalculator.py
More file actions
54 lines (40 loc) · 1.02 KB
/
probabilityCalculator.py
File metadata and controls
54 lines (40 loc) · 1.02 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'''
Probability Calculator
'''
# imports
import random
# classes
class Hat:
def __init__(self):
self.n = 0
self.ballCount = 0
self.register: List[int] = []
self.average = 0
self.counter = 0
self.sum = 0
# setters
def setN(self):
self.n = int(input('What is n? '))
# getters
def getN(self):
return self.n
# funcs
def pickBalls(self):
self.ballCount = random.randint(1, self.n + 1)
print(f'Number of picked balls is {self.ballCount}. ')
def main(self):
self.setN()
for _ in range(1000):
self.pickBalls()
self.register.append(self.ballCount)
for item in self.register:
self.counter +=1
self.sum += item
self.average = self.sum/self.counter
print(f'Average pick with {self.n} is: {self.average}. ')
# main-func
def main():
h = Hat()
h.main()
# calling main
main()