-
Notifications
You must be signed in to change notification settings - Fork 0
/
9.10T.py
33 lines (27 loc) · 805 Bytes
/
9.10T.py
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
from random import random
def main():
printIntro()
n = getInputs()
tauApprox = simNThrows(n)
printSummary(n, tauApprox)
def printIntro():
print("\nThis thing simulates throws of darts at a dart board.")
print("It's doing this in order to approximate the constant Tau.")
def getInputs():
n = int(input("\nHow many darts should be thrown? "))
return n
def simNThrows(n):
h = 0
for i in range(n):
x = 2 * random() - 1
y = 2 * random() - 1
#print(x, y)
if x ** 2 + y ** 2 <= 1:
h += 1
print(h)
tauApprox = 8 * (h / n)
print(tauApprox)
return tauApprox
def printSummary(n, tauApprox):
print("\nThe approximation of Tau after {} throws is {}\n".format(n, tauApprox))
if __name__ == '__main__': main()