In [1]:

```
d1 = 90 # demand for first quarter
d2 = 100 # demand for second quarter
d3 = 80 # demand for third quarter
sa = (d1+d2+d3)/3 # simple average
print "Forecast = %d"%(sa)
```

In [2]:

```
d1 = 300 # demand for july
d2 = 350 # demand for august
d3 = 400 # demand for september
d4 = 500 # demand for october
d5 = 600 # demand for november
d6 = 700 # demand for december
# assuming n = 3 , where n is number of time period
forecast = (d6+d5+d4)/3 # forecast
print "Forecast = %d"%(forecast)
```

In [3]:

```
d1 = 500 # demand for october
d2 = 600 # demand for november
d3 = 700 # demand for december
w1 = 0.25 # relative weight with december
w2 = 0.25 # relative weight with november
w3 = 0.5 # relative weight with october
f = w1*d1 + w2*d2 + w3*d3 # forecast
print "Forecast by weighted moving average = %d"%(f)
```

In [4]:

```
from math import ceil
alpha = 0.7 # smoothing coefficient
d1 = 250 # demand for november
d2 = 300 # demand for december
f1 = 200 # forecast for november
f2 = alpha*d1 + (1-alpha)*f1 # forecast for december
f3 = alpha*d2 + (1-alpha)*f2 # forecast for january
f3 = ceil(f3)
print "Forecast for january = %d units"%(f3)
```

In [5]:

```
from __future__ import division
from math import sqrt
s = 600 # set up cost per lot in Rs
c = 6 # unit cost of item in Rs
a = 100000 # annual demand for item
i = 25 # annual carrying charges of average inventory
i = 25/100
k = c*i # carrying cost factor in unit/year
n = sqrt(2*s*a/k) # most economic lot size
tc = a*c + s*a/n + k*n/2 # total cost in Rs
print "Total cost = Rs %0.2f"%(tc)
# 'Answers vary due to round off error'
```

In [6]:

```
from math import sqrt
a = 8000 # annual requirement of parts
c = 60 # unit cost of part in Rs
r = 150 # ordering cost per lot in Rs
i = 30 # annual carrying charges of average inventory
i = 30/100
k = i*c # carrying cost per unit per year
n = sqrt(2*r*a/k) # most economical order quantity
print "Most economical ordering quantity = %d units"%(n)
```

In [7]:

```
from math import sqrt
a = 12000 # annual requirement
c = 5 # unit cost of part
s = 60 # set up cost per lot
p = 18750 # production rate per year
i = 20 # inventory carrying cost
i = 20/100
k = i*c # carrying cost per unit per year
n = sqrt(2*s/(1/a-1/p)*k) # Most economic lot size
print "Most economic lot size = %d parts"%(n)
```

In [8]:

```
from math import sqrt
a = 15625 # annual requirement of parts
c = 12 # unit cost of part in Rs
r = 60 # ordering cost per lot in Rs
k = 1.2 # inventory carrying cost per unit
n = sqrt(2*r*a/k) # economical order quantity
oc = r*a/n # ordering cost in Rs
cc = k*n/2 # carrying cost in Rs
tc = oc + cc # total inventory cost in Rs
print " Economical order quantity = %d units\n order cost = Rs %d\n carrying cost = Rs %d\n Total inventory cost = Rs %d"%(n , oc , cc , tc)
```

In [9]:

```
from math import sqrt
# case a
a = 50 # annual requirement of parts in tonnes
c = 500 # unit cost of part in Rs
r = 100 # ordering cost per order in Rs
i = 20 # inventory carrying cost
i = i/100
d = 2 # discount of purchase cost in percent
k = i*c # inventory carrying cost per unit
n1 = sqrt(2*r*a/k) # economical order quantity
oc1 = r*a/n1 # ordering cost in Rs
cc1 = k*n1/2 # carrying cost in Rs
tc1 = oc1 + cc1 # total inventory cost in Rs
# case b
n2 = 25 # order per lot
oc2 = r*a/n2 # ordering cost in Rs
cc2 = k*n2/2 # carrying cost in Rs
tc2 = oc2 + cc2 # total inventory cost in Rs
i = tc2-tc1 # increase in cost in Rs
d_o = d*c*a/100 # discount offered
print " Increase in inventory cost = Rs %d\n Discount offered = Rs%d"%(i,d_o)
print " offer is worth accepting"
```

In [10]:

```
from math import sqrt
a = 1000000 # annual requirement of parts
r = 32 # ordering cost per lot in Rs
k = 4 # inventory carrying cost per unit
d1 = 250 # number of working days
d2 = 2 # days for safety stock
d3 = 4 # lead time in days
eoq = sqrt(2*r*a/k) # economical order quantity
oc = r*a/eoq # ordering cost in Rs
cc = k*eoq/2 # carrying cost in Rs
tc = oc + cc # total inventory cost in Rs
ss = a*d2/d1 # safety stock
ro_p = ss+eoq*d3 # reorder point
print " Economic order qunantity = %d components\n Re-order point = %d components"%(eoq ,ro_p)
```