-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab3.py
55 lines (39 loc) · 1.08 KB
/
lab3.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import random
#josue ruiz
def mc_runs():
print("Monte Carlo with the following inputs")
print("10000 runs: " + str(m_carlo(10 ** 4)))
print("100000 runs: " + str(m_carlo(10 ** 5)))
print("1000000 runs: " + str(m_carlo(10 ** 6)))
def m_carlo(n):
counter = 0
for i in range(n):
result = (random.uniform(-1, 1)) ** 2 + (random.uniform(-1, 1)) ** 2
if result <= 1:
counter += 1
else:
continue
return 4 * counter / (1.0 * n)
def sales():
print("%2f" % salesRecieptPrint(80, 125, 45.5))
print("%2f" % salesRecieptPrint(95, tax=.105))
print("%2f" % salesRecieptPrint(12, 5.5, 6.5, 7.5, 9.0, tax=.07))
def salesRecieptPrint(*cost, tax=0.08):
sum=0
for i in cost:
sum = sum + i
return sum + (sum * tax)
def error():
print("Goodbye!")
switch = {
"1": mc_runs,
"2": sales,
}
def main():
print("CS 299 Lab 3")
print("1) Monte Carlo")
print("2) Sales")
choice = input("Enter a choice: \n")
switch.get(str(choice), error)()
if __name__ == "__main__":
main()