In [1]:

```
import math
from __future__ import division
#Variable declaration
p1=1; # Initial pressure of fluid in MPa
T1=250; # Initial temperture of fluid in degree celcius
V=0.28; # Volume of container in m^3
p2=0.35; # Initial pressure of the fluid in MPa
# (a).Water
v1=0.2327; # specific volume of vapour from steam table at state 1 in m^3/kg
v2=v1; # constant volume process
vf2=0.001079; vfg2=0.5232; # specific volume of vapour from steam table at state 2 in m^3/kg
#Calculation for (a)
m=V/v1; # mass of steam
x2=(v2-vf2)/vfg2; # quality of steam at state 2
t2=138.88; # Final temperature of fluid in degree celcius (saturation temperature at p2)
# following are the values taken from steam tables
u1=2709.9; # specific internal energy at state 1 in kJ/kg
s1=6.9247; # Specific entropy at state 1 in kJ/kg K
uf2=582.95; ug2=2548.9; # specific internal energy at state 2 in kJ/kg
sf2=1.7245; sg2=6.9405; # Specific entropy at state 2 in kJ/kg K
u2=(1-x2)*uf2+x2*ug2; # specific internal energy at state 2
s2=(1-x2)*sf2+x2*sg2; # specific enropy at state 2
Q=m*(u2-u1); # Heat transferred
S21=m*(s2-s1); # Entropy change
#Result for (a)
print "(a).Water","Final Temperature = ",t2,"oC","\nHeat transferred = ",round(Q,3),"kJ (answer mentioned in the textbook is wrong)"
print "Entropy change = ",round(S21,3),"kJ/kg K (round off error)"
#Calculation for (b)
# (b).Air
Cvo=0.7165; # Specific heat at constant volume in kJ/kg K
R=0.287; # characteristic gas constant of air in kJ/kg K
m=(p1*10**3*V)/(R*(T1+273)); # Mass of air
T2=(p2/p1)*(273+T1); # Final temperature of air
Q=m*Cvo*(T2-(T1+273)); # Heat transferred
S21=m*Cvo*math.log (T2/(273+T1)); # Change in entropy
#Result for (b)
print "\n(b).Air","Final Temperature = ",round(T2,0),"oC","\nHeat transferred = ",round(Q,0),"kJ (roundoff error)"
print "Entropy change = ",round(S21,3),"kJ/kg K (round off error)"
```

In [2]:

```
import math
from __future__ import division
#Variable declaration
p1=1.0021; # Initial pressure of the fluid in MPa
T1=180; # Initial temperature of the fluid in degree celcius
m=0.5; # Mass of the fluid in kg
p2=p1; # Constant pressure process
# (a).Steam
x1=0.8; # Quality of the steam at state 1
# Following are the values taken from steam table
vf1=0.001127; vfg1=0.1929; # specific volume of the steam in m^3/kg
hf1=763.2; hfg1=2015; # specific enthalpy in kJ/kg
sf1=2.1396; sfg1=4.4460; # specific entropy in kJ/kg K
#Calculation for (a)
v1=vf1+x1*vfg1; # specific volume in m^3/kg
h1=hf1+x1*hfg1; # specific enthalpy in kJ/kg
s1=sf1+x1*sfg1; # specific entropy in kJ/kg K
v2=2*v1; # Final volume of the fluid
t2=410.5; # Final temperature of steam in degree celcius (from superheated steam table)
h2=3286.4; # specific enthalpy in kJ/kg
s2=7.525; # specific entropy in kJ/kg K
S21=m*(s2-s1); # Change in entropy
W=m*p1*10**3*(v2-v1); # Work done
Q=m*(h2-h1); # Heat transferred
#Result for (a)
print "(a).Steam","Final Temperature = ",t2+273,"K","\nChange in entropy = ",S21,"kJ/K (Error in textbook)"
print "Work done = ",round(W,1),"kJ","\nHeat transferred = ",Q,"kJ"
#Calculation for (b)
# (b).Air
Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K
R=0.287; # characteristic gas constant of air in kJ/kg K
V1=m*R*(T1+273)/(p1*10**3); # Initil volume
V2=2*V1; # Final volume
T2=(T1+273)*V2/V1; # Final temperature
S21=m*Cpo*math.log (V2/V1); # Change in entropy
W=p1*10**3*(V2-V1); # Work done
Q=m*Cpo*(T2-(T1+273));# Heat transferred
#Result for (b)
print "\n(b).Air","Final Temperature = ",T2,"K","\nChange in entropy = ",round(S21,3),"kJ/K"
print "Work done = ",round(W,0),"kJ","\nHeat transferred = ",round(Q,1),"kJ"
```

In [3]:

```
import math
from __future__ import division
#Variable declaration
m=1.5; # Mass of the fluid in kg
p1=1; # Initial pressure of fluid in bar
T1=150; # Initial temperture of fluid in degree celcius
v2=0.3; # Final specific volume in m^3/kg
# (a).Steam
# Following are the values taken from steam table
u1=2582.8; # specific internal energy in kJ/kg
s1=7.6134; # specific entropy in kJ/kg K
vf2=0.001091; vfg2=0.3917; # specific volume of the steam in m^3/kg
sf2=1.8418; sfg2=4.9961; # specific entropy in kJ/kg K
uf2=631.7; ufg2=1927.8; # specific internal energy in kJ/kg
#Calculation for (a)
x2=(v2-vf2)/vfg2; # Quality of steam at state 2
s2=sf2+x2*sfg2; # specific entropy in kJ/kg K
u2=uf2+x2*ufg2; # specific internal energy in kJ/kg
S21=m*(s2-s1); # Change in entropy
U21=m*(u2-u1); # Change in internal energy
Q=(T1+273)*(S21); # Heat transferred
W=Q-U21; # Work done
#Result for (a)
print "(a).Steam","\nChange in internal energy = ",round(U21,0),"kJ"
print "Change in entropy = ",round(S21,4),"kJ/K","\nWork done = ",round(W,1),"kJ","\nHeat transferred = ",round(Q,1),"kJ"
#Calculation for (b)
# (b).Air
U21=0; # From fig 7.6
R=0.287; # characteristic gas constant of air in kJ/kg K
v1=(R*(T1+273))/(p1*10**2); # initial specific volume
S21=m*R*math.log (v2/v1); # Change in entropy
Q=(T1+273)*(S21); # Heat transferred
W=Q; # Work done
#Result for(b)
print "\n(b).Air","\nChange in internal energy = ",round(U21,0),"kJ"
print "Change in entropy = ",round(S21,4),"kJ/K","\nWork done = ",round(W,1),"kJ","\nHeat transferred = ",round(Q,1),"kJ"
```

In [4]:

```
#Variable declaration
m=1.5; # Mass of the fluid in kg
p1=1.6; # Initial pressure of fluid in MPa
T1=250; # Initial temperture of fluid in degree celcius
p2=150; # Initial pressure of the fluid in kPa
# (a).Steam
# Following are the values taken from steam table
# state 1 is superheated
u1=2692.3; # specific internal energy in kJ/kg
s1=6.6732; # specific entropy in kJ/kg K
v1=0.14184; # specific volume of the steam in m^3/kg
# State 2 is wet (s1=s2<sg2)
T2=111.37; # Final temperature of steam in degree celcius
sf2=1.4336; sfg2=5.7897; # specific entropy in kJ/kg K
uf2=466.94; ufg2=2052.7; # specific internal energy in kJ/kg
#Calculation for (a)
x2=(s1-sf2)/sfg2; # Quality of steam at state 2
u2=uf2+x2*ufg2; # specific internal energy in kJ/kg
W=-m*(u2-u1);# Work done
#Result for (a)
print "(a).Steam","\nFinal temperature of steam =",T2+273,"K","\nWork done = ",round(W,1),"kJ"
#Calculation for (b)
# (b).Air
Cvo=0.7165; # Specific heat at constant volume in kJ/kg K
k=1.4; # index of reversible adiabatic process
T2=(T1+273)*((p2*10**-3)/p1)**((k-1)/k); # Final temperature of air
W=-m*Cvo*(T2-(T1+273)); # Work done
#Result for (b)
print "(b).Air","\nFinal temperature of steam =",round(T2,1),"K","\nWork done = ",round(W,1),"kJ"
```

In [5]:

```
import math
from __future__ import division
#Variable declaration
m=1.5; # Mass of the fluid in kg
p1=1.6; # Initial pressure of fluid in MPa
T1=250; # Initial temperture of fluid in degree celcius
p2=150; # Initial pressure of the fluid in kPa
n=1.25; # Index of polytropic process
# (a).Steam
# Following are the values taken from steam table
# state 1 is superheated
u1=2692.3; # specific internal energy in kJ/kg
s1=6.6732; # specific entropy in kJ/kg K
v1=0.14184; # specific volume of the steam in m^3/kg
#Calculation for (a)
v2=v1*(p1/(p2*10**-3))**(1/n); # specific volume of the steam at state 2
# State 2 is wet
T2=111.37; # Final temperature of steam in degree celcius
vf2=0.0010531; vfg2=1.1582; # specific volume of the steam in m^3/kg
x2=(v2-vf2)/vfg2; # Quality of steam at state 2
sf2=1.4336; sfg2=5.7897; # specific entropy in kJ/kg K
uf2=466.94; ufg2=2052.7; # specific internal energy in kJ/kg
s2=sf2+x2*sfg2; # specific entropy in kJ/kg K
u2=uf2+x2*ufg2; # specific internal energy in kJ/kg
W=m*((p2*v2)-(p1*10**3*v1))/(1-n); # Work done
Q=m*(u2-u1)+W; # Heat ttransferred
S21=m*(s2-s1); # Change in entropy
#Result for (a)
print "(a).Steam","\nFinal Temperature = ",T2+273,"K","\nChange in entropy = ",round(S21,1),"kJ/K"
print "Work done = ",round(W,0),"kJ","\nHeat transferred = ",round(Q,0),"kJ"
#Calculation for (b)
# (b).Air
R=0.287; # characteristic gas constant of air in kJ/kg K
Cvo=0.7165; # Specific heat at constant volume in kJ/kg K
T2=(T1+273)*((p2*10**-3)/p1)**((n-1)/n); # Final temperature of air
W=m*R*(T2-(T1+273))/(1-n); # Work done
Q=m*Cvo*(T2-(T1+273))+W; # Heat transferred
S21=m*(Cvo+R/(1-n))*math.log (T2/(T1+273)); # Change in entropy
#Result for (b)
print "\n(b).Air","\nFinal Temperature = ",round(T2,0),"K","\nChange in entropy = ",round(S21,3),"kJ/K"
print "Work done = ",round(W,0),"kJ","\nHeat transferred = ",round(Q,1),"kJ"
```

In [6]:

```
#Variable declaration
m=1; # Massflow rate of the steam in kg/s
p1=3.5; # Pressure at inlet in MPa
T1=400; # Temperature at inlet in degree celcius
V1=250; # Velocity of stesm at inlet in m/s
p2=50; # Pressure at outlet in kPa
T2=100; # Temperature at outlet in degree celcius
V2=30; # Velocity of stesm at outlet in m/s
# For actual expansion in the turbine
h1=3222.3; h2=2682.5; # specific enthalpy in kJ/kg at inlet and exit
#Calculation
wa=h1-h2+(V1**2-V2**2)/2000; # Work done
W=m*wa; # Power output
# For reversible adiabatic expansion
# Following are the values taken from steam table
s1=6.8405; # specific entropy in kJ/kg K
s2s=s1; # Isentropic expansion
sf2=1.091; sfg2=6.5029; # specific entropy in kJ/kg K
hf2=340.49; hfg2=2305.4; # specific enthalpy in kJ/kg
x2s=(s1-sf2)/sfg2; # Quality of steam at state 2
h2s=hf2+x2s*hfg2; # specific enthalpy in kJ/kg
ws=h1-h2s+(V1**2-V2**2)/2000; # Isentropic Work done
eff_isen=wa/ws; # Isentropic efficiency of the turbine
#Result
print "Power output of the turbine = ",round(W,0),"kW (Error in textbook)"
print "Isentropic efficiency of the turbine = ",round(eff_isen*100,1),"% (Error in textbook)"
```

In [7]:

```
import math
from __future__ import division
#Variable declaration
m=1; # Massflow rate of the steam in kg/s
p1=3.5; # Pressure at inlet in bar
T1=160; # Temperature at inlet in degree celcius
p2=1; # Pressure at outlet in bar
Cpo=1.005; # Specific heat at constant pressure in kJ/kg K
eff_isen=0.85; # Isentropic efficiency of the turbine
k=1.4; # index of isentropic process
#Calculation
T2s=(T1+273)*(p2/p1)**((k-1)/k); # Final temperature after isentropic expansion
Ws=m*Cpo*((T1+273)-T2s); # Isentropic power developed
Wa=eff_isen*Ws; # Actual power developed
T2=(T1+273)-(Wa/(m*Cpo)); # Final temperature after expansion
#Result
print "Actual power developed =",round(Wa,0),"kW (Error in textbook)",
print "\nFinal temperature after expansion = ",round(T2,1),"K(Roundoff error)"
```

In [8]:

```
#Variable declaration
m=0.05; # mass flowrate of Freon 12 in kg/s
p1=300; # Pressure of Freon 12 at inlet in kpa
t1=5; # Temperature of Freon 12 at inlet in degree celcius
p2=1.2; # Pressure of Freon 12 at outlet in MPa
t2=80; # Temperature of Freon 12 at outlet in degree celcius
W=-2.3; # Power consumption of compressor in kW
# (a).Heat transfer from the body of compressor to environment
# From the table of properties of Freon 12
h1= 190.8; h2=230.4; # specific enthalpy in kJ/kg
s1=0.71; s2=0.7514 # specific entropy in kJ/kg K
#Calculation for (a)
Q=m*(h2-h1)+W; # Heat transfer
#Result for (a)
print "(a).Heat transfer from the body of compressor to environment =",Q,"kW"
#Calculation for (b)
# (b).Adiabatic efficiency of the compressor
# For adiabatic compression p2=1.2Mpa,s2s=s1
t2s=61.7;# Temperature of Freon 12 at outlet in degree celcius
h2s=216.14; # specific enthalpy in kJ/kg
ws=(h2s-h1); # Reversible adiabatic work
wa=W/m; # Actual work
eff_com=abs (ws/wa); # Adiabatic efficiency
#Result for (b)
print "\n(b).Adiabatic efficiency of the compressor = ",round(eff_com*100,0),"%"
```

In [9]:

```
#Variable declaration
p1=1; # Pressure of air at inlet of compressor in bar
T1=30; # Temperature of air at inlet of compressor in degree celcius
p2=12; # Delivery pressure of air in bar
T2=400; # Temperature of air at inlet of compressor in degree celcius
V2=90; # Velocity of air at exit in m/s
w=3740; # Power input to compressor in kW
k=1.4; # Index of reversible adiabatic process
Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K
#Calculation
wa=Cpo*(T2-T1)+V2**2/2000; # Actual specific work input
m=w/wa; # Mass flow rate of air
T2s=(T1+273)*(p2/p1)**((k-1)/k);# Isentropic discharge temperature
ws=Cpo*(T2s-(T1+273))+V2**2/2000; # Isentropic work
eff_com=ws/wa; # Isentrpic efficiency
#Result
print "Isentropic discharge temperature = ",round(T2s,1),"K","\nIsentrpic efficiency of compressor =",round(eff_com*100,0),"%"
```

In [10]:

```
import math
from __future__ import division
#Variable declaration
p1=3; # Pressure of fluid at inlet in bar
T1=150; # Temperature of fluid at inlet in degree celcius
V1=90; # Velocity of fluid at inlet in m/s
eff_nozzle=0.85; # Nozzle efficiency
k=1.4; # Index of reversible adiabatic process
p2=1/3*p1;
# (a).Steam
# Following are taken from steam table
h1=2761; # specific enthalpy in kJ/kg
s1=7.0778;# specific entropy in kJ/kg K
s2s=s1; # Isentropic process
sf2s=1.3026; sfg2s=6.0568;# specific entropy in kJ/kg K
hf2=417.46; hfg2=2258; # specific enthalpy in kJ/kg
#Calculation for (a)
x2s=(s2s-sf2s)/sfg2s; # Quality of steam
h2s=hf2+x2s*hfg2;
V2s=math.sqrt (2000*(h1-h2s)+V1**2); # Isentropic Velocity
V2=math.sqrt (eff_nozzle) *V2s; # Actual nozzle exit velocity
#Result for (a)
print "(a).Steam","\nActual nozzle exit velocity = ",round(V2,1),"m/s (round off error)"
#Calculation for (b)
# (b).Air
Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K
T2s=(T1+273)*(p2/p1)**((k-1)/k); # Isentropic temperature
V2s=math.sqrt ((2000*Cpo*((T1+273)-T2s))+V1**2); # Isentropic Velocity and (answer mentioned in the textbook is wrong)
V2=math.sqrt (eff_nozzle) *V2s; # Actual nozzle exit velocity
#Result for (b)
print "\n(b).Air","\n Actual nozzle exit velocity = ",round(V2,1),"m/s (answer mentioned in the textbook is wrong)"
```

In [11]:

```
#Variable declaration
p1=200; # Pressure of fluid at inlet in kPa
T1=200; # Temperature of fluid at inlet in degree celcius
V1=700; # Velocity of fluid at inlet in m/s
V2=70; # Velocity of fluid at outlet in m/s
# (a).Reversible Adiabatic process
# state of steam entering diffuser (superheated)
h1=2870.5;# specific enthalpy in kJ/kg
s1=7.5066; # specific entropy in kJ/kg K
#Calculation for (a)
h2=h1+(V1**2-V2**2)/2000; # From first and second laws
s2=s1; # Isentropic peocess
# From superheated table
p2s=550; # Pressure of fluid at outlet in kPa
T2=324; # Temperature of fluid at outlet in degree celcius
#Result for (a)
print "(a).Reversible adiabatic process","\nPressure of fluid at outlet = ",p2s,"kPa"
print "Temperature of fluid at outlet =",T2,"oC"
#Calculation for (b)
# (b).Actual diffusion
# for the same change in K.E, from first law
h2=3113.1;# specific enthalpy in kJ/kg
p2=400; # Actual exit pressure in kPa
t2=322.4; # from superheated table in degree celcius
eff_d=(p2-p1)/(p2s-p1); # Diffuser efficiency
#Result for (b)
print "\n(b).Actual diffusion","\nThe exit temperature =",t2,"oC","\nDiffuser efficiency = ",round(eff_d*100,0),"%"
```

In [12]:

```
import math
from __future__ import division
#Variable declaration
p1=1; # Pressure of fluid at inlet in bar
T1=60; # Temperature of fluid at inlet in degree celcius
p2=2.8; # Pressure of fluid at outlet in bar
eff_d=0.80; # Diffuser efficiency
k=1.4; # Index of reversible adiabatic process
Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K
#Calculation
# (a).Actual Diffuser
p2s=((p2-p1)/eff_d)+p1; # Isentropic pressure
T2=(T1+273)*(p2s/p1)**((k-1)/k); # Exit temperature
V1=math.sqrt (2000*Cpo*(T2-(T1+273))); # Initial Velocity
#Result for (a)
print "(a).Actual Diffuser","\nTemperature of air leaving diffuser =",round(T2,1),"K"
print "Initial Velocity =",round(V1,1),"m/s"
#Calculation for (b)
# (b).Reversible Adiabatic diffuser
T2s=(T1+273)*(p2/p1)**((k-1)/k); # Isentropic exit temperature
V1=math.sqrt (2000*Cpo*(T2s-(T1+273))); # Initial Velocity
#Result for (b)
print "\n(b).Reversible Adiabatic diffuser","\nTemperature of air leaving diffuser =",round(T2s,0),"K"
print "Initial Velocity =",round(V1,1),"m/s"
```

In [13]:

```
#Variable declaration
m=18; # mass flow rate of air in kg/s
p1=3.6; # Pressure of fluid at inlet of turbine in MPa
T1=800; # Temperature of fluid at inlet of turbine in Kelvin
V1=100; # Velocity of fluid at inlet of turbine in m/s
V2=150; # Velocity of fluid at outlet of turbine in m/s
W=3.6; # Power output of turbine in MW
p3=1.01; # pressure at diffuser outlet in bar
k=1.4; # Index of reversible adiabatic process
Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K
#Calculation
# (a) Pressure at diffuser inlet
T2=((Cpo*T1)-((W*10**3)/m+(V2**2-V1**2)/2000))/Cpo; # Temperature at outlet of turbine
T3=(T2+273)+((V2**2)/(2*Cpo*10**3)); # Temperature of fluid at diffuser inlet
p2=p3*((T2+273)/T3)**(k/(k-1)); #pressure at diffuser inlet
#Result
print "(a).pressure at diffuser inlet =",round(p2,3),"bar"
```

In [14]:

```
#Variable declaration
T1=35; # Temperature of freon 12 before throttling in degree celcius
T2=5; # Temperature of freon 12 after throttling in degree celcius
# from property table of freon 12
h1=69.49;# specific enthalpy in kJ/kg
hf2=40.66; hfg2=148.86; # specific enthalpy in kJ/kg
h2=h1; # throttling process
#Calculation
x2=(h2-hf2)/hfg2; # Quality of Freon 12 vapour
#Result
print "Quality of Freon 12 vapour = ",round(x2,3)
```

In [15]:

```
#Variable declaration
p2=276; # Pressure at inlet in kPa
p=6.5; # gauge pressure at outlet in cm Hg
T3=110; # Temperature at outlet in degree celcius
pa=756; # Barometric pressure in mm Hg
mc=760;# Mass of condensed steam in g
ms=25; # Mass of separated water in g
den=13600; # Density of mercury in kg/m^3
g=9.81; # Acceleration due to gravity in m/s^2
#Calculation
z=(pa*10**-3)+(p*10**-2);# absolute pressure in m Hg
p3=den*g*z; # Pressure after throttling
h3=2697.4;# specific enthalpy in kJ/kg
hf2=545.31; hfg2=2175.2; # specific enthalpy in kJ/kg
x2=(h3-hf2)/hfg2; # Quality of steam
x1=(mc/(mc+ms))*x2; # Quality of steam in the main line
#Result
print "Quality of steam in the main line =",round(x1,4)," (roundoff error)"
```