In [11]:

```
#example 1
#calculating mass flow rate in kg/s
import math
R=0.287 #in kJ/kg-K
T=25 #temperature in celsius
P=150 #pressure in kPa
v=R*(T+273.15)/P #specific volume in m^3/kg
D=0.2 #diameter of pipe in metre
A=math.pi*D**2/4 #cross sectional area in m^2
V=0.1 #velocity of air in m/s
m=V*A/v #mass flow rate in kg/s
print"\n hence,the mass flow rate is",round(m,4),"kg/s"
```

In [13]:

```
#example 2
#work done for adding the fluid
P=600 #pressure in kPa
m=1 #in kg
v=0.001 #specific volume in m^3/kg
W=P*m*v #necessary work in kJ for adding the fluid
print" \n hence,the work involved in this process is",round(W,4),"kJ"
```

In [15]:

```
#example 3
#rate of flow of water
hir=441.89 #in kJ/kg for refrigerant using steam table
her=249.10 #in kJ/kg for refrigerant using steam table
hiw=42 #in kJ/kg for water using steam table
hew=83.95 #in kJ/kg for water using steam table
mr=0.2 #the rate at which refrigerant enters the condenser in kg/s
mw=mr*(hir-her)/(hew-hiw) #rate of flow of water in kg/s
print"\n hence,the rate at which cooling water flows thorugh the condenser is",round(mw,3),"kg/s"
```

In [19]:

```
#example 4
#determining quality of steam
hi=2850.1 #initial specific heat enthalpy for steam in kJ/kg
Vi=50 #initial velocity of steam in m/s
Ve=600 #final velocity of steam in m/s
he=hi+Vi**2/(2*1000)-Ve**2/(2*1000) #final specific heat enthalpy for steam in kJ/kg
hf=467.1 #at final state in kJ/kg
hfg=2226.5 #at final state in kJ/kg
xe=(he-hf)/hfg #quality of steam in final state
print" \n hence, the quality is",round(xe,2)
```

In [2]:

```
#example 4E
#determining quality of steam
hi=1227.5 #initial specific heat enthalpy for steam in Btu/lbm
Vi=200 #initial velocity of steam in ft/s
Ve=2000 #final velocity of steam in ft/s
he=hi+Vi**2/(2*32.17*778)-Ve**2/(2*32.17*778) #final specific heat enthalpy for steam in Btu/lbm
hf=198.31 #at final state in Btu/lbm
hfg=958.81 #at final state in Btu/lbm
xe=(he-hf)/hfg #quality of steam in final state
print" \n hence, the quality is",round(xe,2)
```

In [23]:

```
#example 5
#quality of ammonia leaving expansion valve
hi=346.8 #specific heat enthalpy for ammonia at initial state in kJ/kg
he=hi #specific heat enthalpy for ammonia at final state will be equal that at initial state because it is a throttling process
hf=134.4 #at final state in kJ/kg
hfg=1296.4#at final state in kJ/kg
xe=(he-hf)*100/hfg #quality at final state
print"\n hence,quality of the ammonia leaving the expansion valve is",round(xe,2),"%"
```

In [28]:

```
#example 6
#power output of turbine in kW
hi=3137 #initial specific heat of enthalpy in kJ/kg
he=2675.5 #final specific heat of enthalpy in kJ/kg
Vi=50.0 #initial velocity of steam in m/s
Ve=100 #final velocity of steam in m/s
Zi=6 #height of inlet conditions in metres
Ze=3 #height of exit conditions in metres
m=1.5 #mass flow rate of steam in kg/s
g=9.8066 #acc. due to gravity in m/s^2
Qcv=-8.5 #heat transfer rate from turbine in kW
Wcv=Qcv+m*(hi+Vi**2/(2*1000)+g*Zi/1000)-m*(he+Ve**2/(2*1000)+g*Ze/1000) #power output of turbine in kW
print"\n hence,the power output of the turbine is",round(Wcv,1),"kW"
```

In [30]:

```
#example 7
#heat transfer rate in aftercooler
V1=0 #we assume initial velocity to be zero because its given that it enters with a low velocity
V2=25.0 #final velocity with which carbon dioxide exits in m/s
h2=401.52 #final specific enthalpy of heat when carbon dioxide exits in kJ/kg
h1=198 #initial specific enthalpy of heat in kJ/kg
w=h1-h2-V2**2/(2*1000) #in kJ/kg
Wc=-50 #power input to the compressor in kW
m=Wc/w #mass flow rate of carbon dioxide in kg/s
h3=257.9 #final specific enthalpy of heat when carbon dioxide flows into a constant pressure aftercooler
Qcool=-m*(h3-h2) #heat transfer rate in the aftercooler in kW
print" \n hence,heat transfer rate in the aftercooler is",round(Qcool,1),"kW"
```

In [39]:

```
#example 8
#Required pump work
m=1.5 #mass flow rate of water in kg/s
g=9.807 #acceleration due to gravity in m/s^2
Zin=-15 #depth of water pump in well in metres
Zex=0 #in metres
v=0.001001 #specific volume in m^3/kg
Pex=400+101.3 #exit pressure in kPa
Pin=90 #in kPa
W=m*(g*(Zin-Zex)*0.001-(Pex-Pin)*v) #power input in kW
print" \n Hence, the pump requires power of input is",-round(W,2),"kW"
```

In [43]:

```
#example 9
#heat tranfer in simple steam power plant
h1=3023.5 #specific heat of enthalpy of steam leaving boiler in kJ/kg
h2=3002.5 #specific heat of enthalpy of steam entering turbine in kJ/kg
x=0.9 #quality of steam entering condenser
hf=226 #in kJ/kg
hfg=2373.1 #in kJ/kg
h3=hf+x*hfg #specific heat of enthalpy of steam entering condenser in kJ/kg
h4=188.5 #specific heat of enthalpy of steam entering pump in kJ/kg
q12=h2-h1 #heat transfer in line between boiler and turbine in kJ/kg
w23=h2-h3 #turbine work in kJ/kg
q34=h4-h3 #heat transfer in condenser
w45=-4 #pump work in kJ/kg
h5=h4-w45 #in kJ/kg
q51=h1-h5 #heat transfer in boiler in kJ/kg
print"\n hence, heat transfer in line between boiler and turbine is",round(q12,1),"kJ/kg"
print"\n hence, turbine work is",round(w23,1),"kJ/kg"
print"\n hence, heat transfer in condenser is ",round(q34,1),"kJ/kg"
print"\n hence, heat transfer in boiler is ",round(q51,1),"kJ/kg"
```

In [45]:

```
#example 10
#analysis of refrigerator
hf4=167.4 #in kJ/kg
hfg4=215.6 #in kJ/kg
h3=241.8 #specific heat of enthalpy of R-134a entering expansion valve
h4=h3 #specific heat of enthalpy of R-134a leaving expansion valve
h1=387.2 #in kJ/kg
h2=435.1 #in kJ/kg
x4=(h3-hf4)/hfg4 #quality of R-134a at evaporator inlet
m=0.1 #mass flow rate in kg/s
Qevap=m*(h1-h4) #rate of heat transfer to the evaporator
Wcomp=-5 #power input to compressor in kW
Qcomp=m*(h2-h1)+Wcomp #rate of heat transfer from compressor
print"\n hence, the quality at the evaporator inlet is ",round(x4,3),
print"\n hence, the rate of heat transfer to the evaporator is ",round(Qevap,2),
print"\n hence, rate of heat transfer from the compressor is",round(Qcomp,2),
```

In [46]:

```
#example 11
#Determining the final temperature of steam
u2=3040.4 #final internal energy in kJ/kg
hi=u2 #in kJ/kg
P2=1.4 #final Pressure in MPa
print"Since, the final pressure is given as 1.4 MPa,we know two properties at the final state and hence,final state can be determined.The temperature corresponding to a pressure of 1.4 MPa and an internal energy of 3040.4 kJ/kg is found to be "
T2=452 #final temperature in Celsius
```

In [48]:

```
#example 12
#Calculating mass flow of steam in tank
V1=0.4 #initial volume fo tank in m^3
v1=0.5243 #initial specific volume in m^3/kg
h1=3040.4 #initial specific enthalpy in kJ/kg
u1=2548.9 #initial specific internal energy in kJ/kg
m1=V1/v1 #initial mass of steam in tank in kg
V2=0.4 #final volume in m^3
print"let x=V*(h1-u2)/v2-m1*(h1-u1).If we assume T2=300C, then v2=0.1823m^3/kg ,u2=2785.2kJ/kg and x=+ve.If we assume T2=350C,then v2=0.2003 m^3/kg, u2=2869.1kJ/kg and x=-ve.Hence,actualt T2 must be between these two assumed values in order that x=0.By interplotation"
T2=342 #final temperature in Celsius
v2=0.1974 #final specific volume in m^3/kg
m2=V2/v2 #final mass of the steam in the tank in kg
m=m2-m1 #mass of steam that flowsinto the tank
print" \n Hence,mass of the steam that flows into the tank is",round(m,3),"kg"
```

In [50]:

```
#example 13
#Calculating mass flow of steam in tank
vf1=0.001725 #in m^3/kg
vf2=0.0016 #in m^3/kg
uf1=368.7 #in kJ/kg
uf2=226 #in kJ/kg
vg1=0.08313 #in m^3/kg
vfg2=0.20381
ug1=1341 #in kJ/kg
ufg2=1099.7 #in kJ/kg
Vf=1 #initial volume of liquid in m^3
Vg=1 #initial volume of vapor in m^3
mf1=Vf/vf1 #initial mass of liquid in kg
mg1=Vg/vg1 #initial mass of vapor in kg
m1=mf1+mg1 #initial mass of liquid in kg
he=1461.1 #in kJ/kg
V=2 #volume of tank in m^3
print"m1u1=mf1*uf1+mg1*ug1.If x2 is the quality,then m2=V/v2=2/(0.00160+0.20381*x2) and u2=uf2+x2*ufg2=226.0+1099.7*x2."
print"Also,m2*(he-u2)=m1*he-m1u1.From this equation,we will get an equation for x2."
x2=((2*1461.1)-(2*226)-(0.00160*634706))/((634706*0.20381)+(2*1099.7)) #quality of ammonia
v2=0.00160+(0.20381*x2) #final specific volume in m^3/kg
m2=V/v2 #final mass of ammonia in kg
m=m1-m2 #mass of ammonia withdrawn
print" \n Hence,mass of ammonia withdrawn is",round(m,1),"kg"
```

In [27]:

```
#example 13E
#Calculating mass flow of steam in tank
vf1=0.02747#in ft3/lbm
vf2=0.02564#in ft3/lbm
uf1=153.89#in Btu/lbm
uf2=97.16#in Btu/lbm
vg1=1.4168 #in ft^3/lbm
vfg2=3.2647#in ft^3/lbm
ug1=576.23#in Btu/lbm
ufg2=472.78#in Btu/lbm
Vf=25 #initial volume of liquid in ft^3
Vg=25 #initial volume of vapor in ft^3
mf1=Vf/vf1 #initial mass of liquid in lbm
mg1=Vg/vg1 #initial mass of vapor in lbm
m1=mf1+mg1 #initial mass of liquid in lbm
he=628 #in Btu/lbm
V=50 #volume of tank in ft^3
print"m1u1=mf1*uf1+mg1*ug1.If x2 is the quality,then m2=V/v2=2/(0.02564+3.2647*x2) and u2=uf2+x2*ufg2=97.16+3.2647*x2."
print"Also,m2*(he-u2)=m1*he-m1u1.From this equation,we will get an equation for x2."
x2=((50*628)-(50*97.16)-(432391*0.02564))/((432391*3.2647)+(50*472.98)) #quality of ammonia
x2=round(x2,6)
v2=0.02564+(3.2647*x2) #final specific volume in ft^3/lbm
v2=round(v2,6)
m2=V/v2 #final mass of ammonia in lbm
m=m1-m2 #mass of ammonia withdrawn
print" \n Hence,mass of ammonia withdrawn is",round(m,1),"lbm"
```