from math import asin, cos, acos, tan
lod=1 #industrial installation load
pf=0.78 #power factor
tf=200 #tariff
md=3.5 #extra maximum demand
ic=500 #installation of capacitor
id=0.15 #interest and depreciation
lf=0.8 #load factor
sinp=ic*id/tf
ph2=asin(sinp)
epf2=cos(ph2)
ph1=acos(pf)
ph1=round(ph1*10**2)/10**2
ph2=round(ph2*10**2)/10**2
q=lod*(tan(ph1)-tan(ph2))
q=round(q*10**4)/10**4
ikva=lod/pf
ikv=round(ikva*(10**5))/10**2
aeu=lod*lf*8760*10**6
eb=ikv*tf+aeu*md
print "(a)\neconomic power factor %.3flagging \n(b) \ncapacitor kVAr to improve the power factor %.4f \n(c) \ninitial kVA %.2fKVA \nannual energy used %0.3ekWh \nelectrical bill Rs%e per year"%(epf2,q,ikv,aeu,eb)
kvc=round((lod*10**3/(round(epf2*1000)/10**3))*10**2)/10**2
ebc=kvc*tf+aeu*md
aidc=q*10**3*ic*id
te=ebc+aidc
asc=eb-te
print "(d)\nKVA after installation of capacitors %.2fKVA \n"%kvc
print "energy bill after installation of capacitor Rs%e per year"%ebc
print "annual interest and depreciation of capacitor bank Rs%.1fper year \ntotal expendition after installation of capacitors Rs%e per year \nannual savings due to installation of capacitors Rs%d per year"%(aidc,te,asc)
ee=5*10**16 #electrical energy requirement
eer=0.1 #energy requirement
i=5*10**6 #investement
n=20 #life time
ec=4.1 #energy cost
r=0.13 #interest rate
dr=r/((1+r)**(n)-1) #depreciation rate
dr=round(dr*10**5)/10**5
tfc=r+dr #total fixed cost
ace=i*tfc #annual cost
ace=round(ace/10**2)*10**2
eb=i*ec #electrical bill with present motor
teb=eb*(1-eer) #electrical bill with efficiency motor
tac=teb+ace #total annual cost with efficiency cost
As=eb-tac #annual saving
print 'part (a)'
print " depreciation rate %.5f \n total fixed charge rate %f\n annual cost of efficiency motor Rs%eper year \n total electrical bill with present motors Rs%eper year \n total electrical bill with efficiency motor Rs.%e \n total annual cost if motors are replaced by high efficiency motors Rs%e per year \n annual saving Rs%d per year"%(dr,tfc,ace,eb,teb,tac,As)
print 'part (b)'
pwf=r/(1-((1+r)**-n)) #present worth factor
pwf=round(pwf*10**5)/10**5
pwm=teb/pwf #present worth annual cost with existing motors
pwm=round(pwm/10**4)*10**4 #present worth with existing motors
pwem=eb/pwf #present worth with efficiency motor
pwem=round(pwem/10**4)*10**4
pwam=teb/pwf
pwam=round(pwam/10**4)*10**4
tpw=pwam+i #total persent worth
print " present worth factor %.5f \n present worth of annual cost with existing motors Rs%e \n present worth of annual cost with new motor Rs%e \n total present worth %e per year"%(pwf,pwem,pwam,tpw)