#calculate the work done in the process
#Initialization of variables
import math
n=1.3
T1=460+60. #R
P1=14.7 #psia
P2=125. #psia
R=1545.
M=29.
#calculations
T2=T1*math.pow((P2/P1),((n-1)/n))
wrev=R/M *(T2-T1)/(1-n)
#results
print '%s %d %s' %("Work done =",wrev,"ft-lbf/lbm")
print '%s' %("The answer is a bit different due to rounding off error in textbook")
#calculate the change in kinetic energy
#Initialization of variables
import math
P2=10. #psia
P1=100. #psia
T1=900. #R
w=50 #Btu/lbm
k=1.39
cp=0.2418
#calculations
T2=T1*math.pow((P2/P1),((k-1)/k))
T2=477
KE=-w-cp*(T2-T1)
#results
print '%s %.1f %s' %("Change in kinetic energy =",KE," Btu/lbm")
#calculate the final temperature of the system
#Initialization of variables
T1=900. #R
P1=100. #psia
P2=10. #psia
#calculations
print '%s' %("From table B-9")
pr1=8.411
pr2=pr1*P2/P1
T2=468. #R
#results
print '%s %d %s' %("Final temperature =",T2,"R ")
#calcuate the final temperature, pressure, enthalpy and the work done in the process
#Initialization of variables
cr=6
p1=14.7 #psia
t1=60.3 #F
M=29.
R=1.986
#calculations
print '%s' %("from table b-9")
vr1=158.58
u1=88.62 #Btu/lbm
pr1=1.2147
vr2=vr1/cr
T2=1050. #R
u2=181.47 #Btu/lbm
pr2=14.686
p2=p1*(pr2/pr1)
dw=u1-u2
h2=u2+T2*R/M
#results
print '%s %d %s' %("final temperature =",T2," R")
print '%s %.1f %s' %("\n final pressure =",p2,"psia")
print '%s %.2f %s' %("\n work done =",dw,"Btu/lbm")
print '%s %.1f %s' %("\n final enthalpy =",h2," Btu/lbm")