-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task 3.py
71 lines (60 loc) · 1.83 KB
/
Task 3.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import random
#Determinestic Inputs
ShortageCost = 100
HoldingCost = 50
SellingPrice = 450
#lists
profitlist = list() #Profit List
x= list() #Demands
#AverageProfit1 = 0
#AverageProfit2 = 0
def random_0to1():
return random.uniform(0, 1)
def get_x():
rand_prob=random_0to1()
if rand_prob>=0 and rand_prob<0.2:
x=0
elif rand_prob>=0.2 and rand_prob<0.6:
x=1
elif rand_prob>=0.6 and rand_prob<0.8:
x=2
elif rand_prob>=0.8 and rand_prob<0.9:
x=3
else :
x=4
return x
for i in range (500) : #i is the Order
x.append(get_x ())
for Order in range (1,3) : #Order is 1 or 2
Avail = 1
for Week in range (500) : #500 Week
Avail += Order
if x[Week]< Avail :
sold = x[Week]
Avail -= x[Week]
loss = Avail * HoldingCost
elif x[Week] > Avail :
sold = Avail
Avail = 0
loss = (x[Week] - sold) * ShortageCost
else :
sold = x[Week]
Avail = 0
loss = 0
revenue = sold * SellingPrice
profit = revenue - (loss)
if profit >= 0 :
profitlist.append(profit)
if Order == 1 :
AverageProfit1 = sum(profitlist) / 500
profitlist.clear()
else :
AverageProfit2 = sum(profitlist) / 500
#Printing Information:
print ("The average profit of 500 weeks :" , "\n")
print ("if the shop owner ordered 1 PC per week :" , AverageProfit1 ,"\n" )
print ("if the shop owner ordered 2 PC per week :" , AverageProfit2 ,"\n" )
if AverageProfit1 > AverageProfit2 :
print("Ordering 1 PC per week is the best decision")
elif AvgProfit1 < AvgProfit2:
print("Ordering 2 PC per week is the best decision")