In [2]:

```
# Variables
p1= 2.; # in bar
v1= 30.; # in litre
T1= 27.+273; # in K
T2= -3.+273; # in K
v2= v1; # in litre
# Calculations
# Gas law p1*v1/T1= p2*v2/T2
p2= p1*v1*T2/(T1*v2); # in bar
# Results
print "The air pressure in the tyre in bar is :",p2
```

In [1]:

```
# Variables
p= 12.; # in bar
p=p*10**5; # in N/m**2
v= 25.; # in m**3
T= 30.+273; # in K
# Part (a) Mass of each gas
#Formula p*v=m*R*T
R_U= 8314.; # in J/kg-mole K
M_N2= 28.016; # in mole
M_O2= 32.; # in mole
M_CO2= 44.; # in mole
# Calculations and Results
R_N2= R_U/M_N2; # in J/kg K
R_O2= R_U/M_O2; # in J/kg K
R_CO2= R_U/M_CO2; # in J/kg K
m_of_N2= p*v/(R_N2*T); # in kg
m_of_O2= p*v/(R_O2*T); # in kg
m_of_CO2= p*v/(R_CO2*T); # in kg
print "The mass of Nitrogen gas stored in the vessel in kg is : %.2f"%(m_of_N2)
print "The mass of Oxygen gas stored in the vessel in kg is : %.2f"%m_of_O2
print "The mass of Carbon dioxide gas stored in the vessel in kg is : %.2f"%round(m_of_CO2)
# Part (b) Molar Volume
# Formula v_molar= M*R*T/p= R_U*T/p
v_molar= R_U*T/p; # in m**3
print "Molar volume of the gas mixture in m**3 is : %.2f"%v_molar
# Part (c) Average density
# rho_avg= total mass/total volume
rho_avg= (m_of_N2+m_of_O2+m_of_CO2)/v; # in kg/m**3
print "density of the gas mixture in kg/m**3 is : %.2f"%rho_avg
```

In [2]:

```
# Variables
Qp = 1230.; # kJ/kg
Qv = 795.; # kJ/kg
t1 = 16.; # in °C
t2 = 96.; # in °C
R_U = 8.314;
# Calculations and Results
delta_T= t2-t1; # in °C
Cp= Qp/delta_T; # in kJ/kg °C
print "The value of Cp in kJ/kg°C",Cp
Cv= Qv/delta_T; # in kJ/kg °C
print "The value of Cv in kJ/kg°C",Cv
R= Cp-Cv; # in kJ/kg °C
print "The value of R in kJ/kg°C",R
molecular_weight= R_U/R;
print "Molecular weight of the gas is : %.3f"%molecular_weight
```

In [2]:

```
import math
from scipy.integrate import quad
# Variables
a= 0.85;
b= 0.00004;
c= 5*10**-5;
T1= 300; # in K
T2= 2300; # in K
gama= 1.5; # the ratio of specific heats
m=1; # in kg
# Calculations and Results
def f1(T):
return a+b*T+c*T**2
delta_H= m* quad(f1,T1,T2)[0]
print "Change in enthalpy in MJ is : %.3f"%(delta_H*10**-3)
# Formula delta_U= integration of m*Cv = integration of m*Cp/gama= delta_H/gama
delta_U= delta_H/gama; # in kJ
print "change in internal energy in MJ is : %.3f"%(delta_U*10**-3)
```

In [4]:

```
# Variables
v= 0.9/3; # in m**3/kg
v= 2*v; # in m**3/kg mole (as M_hydrogen = 2)
T=120+273; # in K
R=8314; # in J/kg mole K
a=2.51*10**4; # in Nm**4/(kg mole)**2
b= 0.0262;
# Calculations and Results
# Part (a)
p= R*T/v; # in N/m**2
p= p*10**-5; # in bar
print "Using perfect gas law the pressure for unit mass of hydrogen in bar is : %.3f"%p
# Part (b)
p= R*T/(v-b)-a/v**2; # N/m**2
p= p*10**-5; # in bar
print "Using Van der waals equation, the pressure in bar is : %.3f"%p
```

In [1]:

```
# Variables
p1= 0.98; # in bar
p2= 0.6; # in bar
v1= 0.45; # in m**3/kg
# Calculations
# Applying Boyle's law
v2= p1*v1/p2; # in m**3/kg
rho2= 1/v2; # in kg/m**3
# Results
print "density of the gas under the changed condition in kg/m**3 is : ",round(rho2,2)
```

In [5]:

```
# Exa 2.7
import math
# Variables
r=5; # in cm
R_U= 8314
T= 27+273; # in K
# Calculations
V= 4./3*math.pi*r**3; # volume of balloon in cm**3
# atmPressure= 75 cm off mercury = 75/76*1.01325
atmPressure= round(75./76*1.01325) ; # in bar
p= atmPressure; # pressure of hydrogen in balloon in bar
p=p*10**5; # in N/m**2
R= R_U/2; # in J/kg K
m1= p*V/(R*T); # in kg
# The volume of air print laced = the volume of balloon, so
R=287;
T=20+273; # in K
m2= p*V/(R*T); # in kg
payload= m2-m1; # in kg
# Results
print "Payload that can be lifted along with the balloon in kg is : %.2f"%payload
```

In [3]:

```
# Variables
AvogadroNo= 6.023*10**23;
n= 5/AvogadroNo; # number of moles
v=10**-6; # in m**3
T= -270+273; # in K
R= 0.287;
# Calculations
p= n*R*T/v; # in kPa
p= p*10**18; # in aPa
# Results
print "The pressure in the space is %.3f aPa"%p;
```

In [13]:

```
# Exa 2.13
import math
from scipy.integrate import quad
# Variables
T1 = 300; # in K
T2 = 900; # in K
m = 2; # in kg
# Calculations
def f3(T):
return 40-600/math.sqrt(T)+7000/T
delta_H=m* quad(f3,T1,T2)[0]
delta_H= delta_H/17.03; # in kJ/kg
# Results
print "Change in enthalpy in kJ/kg is : %.1f"%delta_H
```

In [14]:

```
# Variables
m = 12.; # in kg mol
v = 723.7; # in m**3
T = 140.; # in °C
T = T+273; # in K
rho = 0.644; # in kg/m**3
Ro = 8314; # in J/kg-mole K
# Calculations and Results
# rho= m/v, where m in Kg , so rho= m*M/v
M = rho*v/m;
m = m*M; # in kg
print "Molecular weight is : %.2f"%M
# Part (b)
R = Ro/M; # in J/kg K
print "Gas constant in kJ/kg K is : %.3f"%(R*10**-3)
# Part(c)
p = m*R*T/v; # in N/m**2
p = p*10**-5; # in bar
print "The pressure of the gas in bar is : %.3f"%p
```

In [15]:

```
# Variables
p = 0.98; # in bar
p = p*10**5; # in N/m**2
v = 1000; # in m**3
T = 27+273; # in K
g = 9.8;
M = 2;
Ro = 8314; # in J/kg-mole K
# Calculations
R = Ro/M; # in kg K
m = p*v/(R*T); # in kg
W = m*g; # in N
# Results
print "The load that can be lifted with the air of aerostat in N is : %.2f"%W
```

In [16]:

```
import math
from scipy.integrate import quad
# Variables
T1= 500; # in K
T2= 2000; # in K
m=1; # in kg
# Calculations
def f2(T):
return 11.515-172/math.sqrt(T)-1530/T
delta_H=m* quad(f2,T1,T2)[0]
# Results
print "Change in enthalpy in kcal/kg mole is : %.2f"%delta_H
```

In [1]:

```
from scipy.misc import derivative
# Variables
duBydt= 0.718;
# Calculations
def f1(t):
return 196. + 0.178 * t
Cv = round(derivative(f1,1.0, dx=1e-6),3)
def f2(t):
return 273.351 + 1.005*t
Cp = round(derivative(f2,1.0, dx=1e-6),3)
# Results
print "The value of Cv in kJ/kg-K is : ",Cv
print "The value of Cp in kJ/kg-K is : ",Cp
```