In [1]:

```
from __future__ import division
# Given data
P = 2.15 * 10**5 # in N/m**2
T = 20 # in degree C
T = T + 273 # in K
V = 0.20 # in m**3
R = 0.2927 # in kJ/kg-K
R = R * 10**3 # in J/kg-K
m = (P*V)/(T*R) # in kg
Q = 20*10**3 # in J
C_v = 0.706*10**3 # in J/kg-K
theta = Q/(m*C_v) # in degree C
T = T - 273 # in degree C
T1 = theta + T # new temp. in degree C
print "New temperature = %0.1f degree C " %T1
T1 = T1 + 273 # in K
T = T + 273 # in K
P2 = P * (T1/T) # in N/m**2
P2 = P2 * 10**-3# in kN/m**2
print "New pressure = %0.3f kN/m**2 " %P2
```

In [2]:

```
# Given data
P = 350# in kN/m**2
P = P * 10**3# in N/m**2
m = 1# in kg
m = m * 10**3# in gram
V = 0.35# in m**3
C_p = 1.005# in kJ/kg-K
C_v = 0.710# in kJ/kg-K
R = C_p - C_v# in kJ/kg-K
T = (P*V)/(m*R) # in K
T = T - 273# in degree C
print "The intial temperature = %0.0f K " %(T+273)
T = T + 273# in K
T1 = 316# in degree C
T1 = T1 + 273# in K
P2 = P * (T1/T) # in N/m**2
P2 = P2 * 10**-3# in kN/m**2
print "The final pressure of air = %0.1f kN/m**2 " %P2
T = T - 273# in degree C
T1 = T1 - 273# in degree C
m = m * 10**-3# in kg
Q = m * C_v * (T1-T) # in kJ
print "Heat added = %0.2f kJ " %Q
G = m*C_v * (T1-T) # Gain of internal energy # in kJ
print "Gain of internal energy = %0.2f kJ " %G
G_enthalpy = m*C_p*(T1-T) # Gain of enthalpy in kJ
print "Gain of enthalpy = %0.2f kJ " %G_enthalpy
```

In [3]:

```
# Given data
P = 3.2# in bar
P = P * 10**5# in N/m**2
R = 292.7# in kJ/kg-K
C_p = 1.003# in kJ/kg-K
m = 1#
V1 = 0.3# in m**3
V2 = 2*V1# in m**3
W = P*(V2-V1) # in J
W = W * 10**-3 # in kJ
print "The work done = %0.0f kJ " %W
T1 = (P*V1)/(m*R) # in K
print "The intail Temperature = %0.0f °C " %(T1-273)
T2 = T1*(V2/V1) # in K
print "The final temperature = %0.0f °C " %(T2-273)
Q = m*C_p*(T2-T1) # in kJ
print "The Heat added = %0.0f kJ " %(Q)
# Note: To evaluate the value of Heat added,
# wrong value of T1 is putted (i.e 273 k at place of 328 K), so the answer of Heat added is wrong in the book.
```

In [4]:

```
# Given data
R = 0.29# in kJ/kg-K
R = R * 10**3# in J/kg-K
C_p = 1.005# in kJ/kg-K
T = 185# in degree C
T = T + 273# in K
T2 = 70+273# in K
V1 = 0.23# in m**3
P = 500# in kN/m**2
P = P * 10**3# in N/m**2
m = (P*V1)/(R*T) # in kg
Q = m*C_p*(T2-T) # in kJ
print "Heat transferred = %0.2f kJ " %Q
print "i.e. %0.2f kJ heat has been abstracted from the gas" %(abs(Q))
V2 = V1*(T2/T) # in m**3
W = P * (V2-V1) # in J
W= W*10**-3#in kJ
print "The work done = %0.0f kJ " %W
print "i.e.",round(abs(W),0),"kJ work has been done on the gas "
R= R*10**-3# in kJ/kg-K
C_v = C_p - R# in kJ/kg-K
I_E = m*C_v*(T2-T) # Change in internal energy in kJ
print "Change in internal energy = %0.3f kJ " %I_E
print "i.e.",round(abs(I_E),3),"kJ energy is decrease in internal energy"
```

In [7]:

```
from math import log
# Given data
P1 = 1.1# in MN/m**2
P1 = P1 * 10**6# in N/m**2
V1 = 1.5# in m**3
V2 = 7.5# in m**3
P2 = (P1*V1)/V2# in kN/m**2
P2 = P2 * 10**-6# in MN/m**2
P2 = P2 * 10**3# in kN/m**2
print "The final pressure = %0.0f kN/m**2 " %P2
W = P1*V1*log(V2/V1) # in J
W = W * 10**-4# in kJ
print "The work done = %0.0f kJ " %int(W)
```

In [5]:

```
# Given data
P1 = 2800000# in N/m**2
P1 = P1 * 10**-6# in MN/m**2
C_p = 1.024# in kJ/kg-K
C_v = 0.7135# in kJ/kg-K
V1 = 1# in m**3. (asuumed )
V2 = 5*V1# in m**3
T1 = 220# in degree C
T1 = T1 + 273# in K
Gamma = C_p/C_v#
P2 = (P1*(V1)**Gamma)/((V2)**Gamma) # in MN/m**2
print "The final pressure = %0.3f MN/m**2 " %P2
T2 = (P2/P1)*V2*T1 # in K
print "The final temperature = %0.1f degree C " %(T2-273)
R = C_p-C_v# in kJ/kg-K
W = (R*(T1-T2))/(Gamma - 1) # in kJ
print "Work done = %0.1f kJ " %W
```

In [8]:

```
from math import log10
# Given data
W = 89.947# in kJ
T1 = 240# in degree C
T1=T1+273# in K
T2 = 115# in degree C
T2=T2+273# in K
C_v = W/(T1-T2) # in kJ/kg-K
print "The value of Cv = %0.3f kJ/kg-K " %C_v
V1 = 1# in m**3 (assumed)
V2 = 2*V1# in m**3
# (T1/T2) = (V2/V1)**(Gamma - 1)
Gamma=log10(T1/T2)/log10(V2/V1)+1#
Gamma = 1.4#
C_p = Gamma * C_v# in kJ/kg-K
print "The value Cp = %0.3f kJ/kg-K " %C_p
```

In [9]:

```
# Given data
P = 7# in bar
P = P *10**5# in N/m**2
R = 0.287# in kJ/kg-K
R=R*10**3# in J/kg-K
Gamma = 1.4#
T = 100# in degree C
T = T + 273# in K
V = (R*T)/P# in m**3
print "The volume of one kg of air = %0.3f m**3" %V
C_v = 0.718# in kJ/kg
T=T-273# in degree C
InternalEnergy= C_v*T# in kJ/kg
print "Internal energy of 1 kg air = %0.1f kJ/kg" %InternalEnergy
P1= P# in bar
V1 = 1# in m**3 (assumed)
V2 = 4 * V1# in m**3
T1= T# in degree C
T1=T1+273# in K
P2 = (P * (V1)**Gamma)/((V2)**Gamma) # in N/m**2
print "The final pressure = %0.3f bar " %(P2*10**-5)
T2 = (P2*V2)/(P1*V1)*T1# in K
T2 = T2 - 273# in degree
print "The final temperature = %0.1f degree C " %T2
I_E = C_v * T2# in kJ/kg
print "Internal energy = %0.2f kJ/kg " %I_E
```

In [10]:

```
# Given data
Gamma = 1.41#
C_v = 0.703# in kJ/kg-K
P1 = 105# in kN/m**2
P2 = 2835# in kN/m**2
T1 = 15# in degree C
T1 = T1 + 273# in K
m = 0.2# in kg
# Formula T2/T1 = (P2/P1)**((Gamma-1)/Gamma)
T2 = T1*(P2/P1)**((Gamma-1)/Gamma) # in K
T2 = T2 - 273# in degree C
print "The final temperature = %0.0f degree C " %T2
T2 = T2+273# in K
I_E = m*C_v*(T2-T1) # in kJ
print "Change in internal energy = %0.3f kJ " %I_E
W = I_E# in kJ
print "Work done = %0.3f kJ " %W
# Note: There is an error to calculate the value of T2, and this wrong value is putted to evaluate
# the value of Change in internal energy but the value of Change in internal energy is calculated correct.
```

In [32]:

```
from numpy import pi
# Given data
P1= 100# in N/m**2
T1 = 30# in degree C
T1 = T1 + 273# in K
C_v = 0.718# in kJ/kg-K
#C_v= C_v*10**3# in J/kg-K
R = 287.1# in J/kg-K
d = 15# in cm
l = 20# in cm
V = (pi/4)*(d)**2*l# in cm**3
V = V * 10**-3# in litre
Clear_V = 1.147# clearance volume
Vol = V+Clear_V#volume of air at beginning of compression in litre
ROC = Vol/Clear_V# Ratio of compression
P2 = P1*(Vol/Clear_V)**1.2# in kN/m**2
print "The pressure at the end of compression = %0.1f kN/m**2 " %P2
T2 = (P2*Clear_V*T1)/(P1*Vol) # in K
T2 = T2 - 273# in degree C
T1 = T1 - 273# in degree C
T = T2-T1# in degree C
print "The temperature at the end of compression = %0.1f degree C " %T
T1 = T1 + 273# in K
m = (P1*Vol)/(R*T1) # in kg
I_E = m*C_v*T# in kJ
print "The change in internal energy = %0.3f kJ " %I_E
```

In [11]:

```
# Given data
V1 = 2.5 # in litre
P1 = 1400 # kN/m**2
P2 = 280 # in kN/m**2
T1 = 1100 # in °C
T1 = T1 + 273 # in K
n = 1.28
V2 = V1*(P1/P2)**(1/1.28) # in litres
print "Final volume = %0.1f litres " %V2
T2 = T1*((P2*V2)/(P1*V1)) # in K
T2 = T2 - 273# in degree C
print "Final temperature = %0.0f degree C " %T2
W = (P1* V1 - P2*V2)/(n-1) # in Joules
print "Work done = %0.2f kJ " %(W*10**-3)
```

In [33]:

```
from math import log
# Given data
Gamma = 1.4#
P1 = 780# in kN/m**2
P2 = 100# in kN/m**2
V1 = 750# in cm**3
V1= V1*10**-6# in m**3
V2 = (1/5)*V1# in m**3
n = (log(P1/P2))/(log(V1/V2))
print "The value of index = %0.3f" %n
W = (P1*V2-P2*V1)/(1-n) # in kJ
print "Work done = %0.3f kJ " %W
print "i.e.",round(abs(W),4),"kJ work is done on the gas"
Q = ((Gamma - n)/(Gamma-1)) * (-W) # in kJ
print "Heat rejected during Compression is :",round(Q,4),"kJ or",round(Q*10**3),"joules."
```

In [34]:

```
from math import log
# Given data
T1 = 40# in degree C
T1 = T1 +273# in K
P2 = 50# in bar
P1 = 1# in bar
Gamma = 1.4#
C_v = 0.718# in kJ/kg-K
SpeHeat = 1.005# in kJ/kg-K
HeatSupply= 125.6# in kJ/kg
T2 = T1 * (P2/P1)**((Gamma-1)/Gamma) # in K
C_p = C_v * (T2-T1) # in kJ/kg
del_T = HeatSupply/SpeHeat# in degree C
del_U = C_v * del_T# in kJ/kg
print "Change in internal energy = %0.1f kJ/kg " %del_U
T3 = T2 + del_T# in K
del_Phi = SpeHeat * log(T3/T2) # in kJ/kg-K
print "Change in entropy during constant pressure = %0.3f kJ/kg-K " %del_Phi
```

In [35]:

```
from math import log
# Given data
P1 = 30# in bar
P1= P1*10**5# in N/m**2
V1 = 0.85# in m**3
V2 = 4.25# in m**3
W = P1 *V1 * log(V2/V1) # in Joules
W = W * 10**-3# in kJ
T = 400# in K
del_U = W/T# in kJ/K
print "Change in entropy = %0.3f kJ/K " %del_U
```

In [36]:

```
from math import log
# Given data
C_P = 1.041# in kJ/kg-K
C_V = 0.743# in kJ/kg-K
R = C_P - C_V# in kJ/kg-K
P1 = 140# in kN/m**2
P2 = 1400# in kN/m**2
V1 = 0.14# in m**3
T1 = 25# in degree C
T1 = T1 + 273# in K
Gamma = 1.4#
n = 1.25#
m = (P1 * 10**3 *V1)/(R * 10**3 * T1) # in kg
V2 = V1 * (P1/P2)**(1/n) # in m**3
del_U = C_P * (log(V2/V1)) + C_V * (log(P2/P1)) # in kJ/kg-K
del_U = m * del_U # in kJ/K
print "Part (i)"
print "Change in entropy = %0.4f kJ/K " %del_U
T2 = T1 * (V1/V2)**(n-1) # in K
del_U1 = C_P * (log(T2/T1)) - R*(log(P2/P1)) # in kJ/kg-K
print "Part (ii)"
print "Change in entropy = %0.3f kJ/kg-K " %del_U1
del_U2 = C_V * (log(T2/T1)) + R*(log(V2/V1)) # in kJ/kg-K
print "Part (iii)"
print "Change in entropy = %0.3f kJ/kg-K " %del_U2
del_U3 = C_V * (Gamma-n) * (log(V2/V1)) # in kJ/kg-K
print "Part (iv)"
print "Change in entropy = %0.3f kJ/kg-K " %del_U3
del_U4 = C_V * ((Gamma-n)/(n-1)) * (log(T1/T2)) # in kJ/kg-K
print "Part (v)"
print "change in entropy = %0.3f kJ/kg " %del_U4
del_U5 = C_V * ((Gamma-n)/n) * (log(P1/P2)) # in kJ/kg-K
print "Part (vi)"
print "Change in entropy = %0.3f kJ/kg-k " %del_U5
```

In [37]:

```
from math import log
# Given data
P1 = 1# in bar
P2 = 15# in bar
T1 = 0# in degree C
T1 = T1 + 273# in K
T2 = 200# in degree C
T2 = T2 + 273# in K
C_P = 1.005# in kJ/kg-K
C_V = 0.718# in kJ/kg-K
R = C_P-C_V# in kJ/kg-K
del_U = C_P * (log(T2/T1)) - R*(log(P2/P1)) # in kJ/kg-K
print "Change in entropy = %0.3f kJ/kg-K " %del_U
```

In [38]:

```
from math import log
# Given data
C_V = 2.174# in kJ/kg-K
R = 0.5196# in kJ/kg-K
C_P = C_V+R# in kJ/kg-K
V2 = 1# in m**3
V1 = 8# in m**3
P1 = 0.7# in bar
P2 = 7# in bar
del_U = C_P * (log(V2/V1)) + C_V * (log(P2/P1)) # in kJ/kg-K
m = 0.9# in kg
del_U = m * del_U# in kJ/K
print "Change in entropy = %0.3f kJ/K " %del_U
print "It is a loss of entropy"
```

In [18]:

```
# Given data
C_P = 1.005# in kJ/kg-K
C_V = 0.718# in kJ/kg-K
R = C_P - C_V# in kJ/kg-K
R= R*10**3#in J/kg-K
P1 = 3*10**5#in N/m**2
V1 = 1.5# m**3
T1 = 15# in degree C
T1 = T1 +273# in K
m1 = (P1*V1)/(R* T1) # in kg
m2 = m1+2#final mass of air in kg
P2 = P1 * (m2/m1) # in kN/m**2
T1 = T1 - 273# in degree C
T2 = 0# in degree C
m = 1# in kg
del_U = m * C_P * (T1-T2) # in kJ
print "Total enthapy of air = %0.3f kJ " %del_U
```

In [19]:

```
# Given data
R = 0.287# in kJ/kg-K
P1 = 30# in bar
V1 = 0.12# in m**3
m = 1.8# in kg
U= 8.3143# in kJ/kg-mol-K
T1 = (P1 * 10**5 * V1)/(m*R*10**3) # in K
T1 = T1 - 273# in degree C
print "The temperature = %0.0f degree C " %int(T1)
m_m = U/R# in kg
print "The molecular mass = %0.2f kg " %m_m
V_s = V1/m# in m**3
print "The Specific volume = %0.4f m**3 " %V_s
V_m = V_s * m_m# in m**3
print "Molecular volume = %0.2f m**3 " %V_m
```

In [20]:

```
# Given data
T=15+273#in K
U= 8.3143# in kJ/kg-mol-K
GasConstant = 0.618# in kJ/kg-K
GasVolume= 1# in m**3 (assume)
AirVolume= 1.5*GasVolume# in m**3
P=760# in mm
P= P/750# in bar
P= P*10**5#in N/m**2
MixtureVolume= GasVolume+AirVolume#in m**3
PGM= GasVolume/MixtureVolume*100# in %
print "Percentage of gas by volume in the mixture = %0.0f %%" %PGM
PAM= AirVolume/MixtureVolume*100# in %
print "Percentage of air by volume in the mixture = %0.0f %%" %PAM
M1= U/0.287# in mol
M2= U/0.618# in mol
M= PAM/100*M1+PGM/100*M2# mass of mixture in mol
R= U/M# gas constant in kJ/kg-K
R= R*10**3#in J/kg-K
print "The gas constant = %0.3f kJ/kg-K" %(R*10**-3)
PAM1= PAM*M1/M# in %
print "Percentage of air by mass in the mixture = %0.2f %%" %PAM1
PGM1= PGM*M2/M# in %
print "Percentage of gas by mass in the mixture = %0.2f %%" %PGM1
Rho= P/(R*T) # kg/m**3
print "The density of the gas = %0.3f kg/m**3" %Rho
```

In [39]:

```
import math
from math import log
# Given data
Gamma = 1.4#
P1 = 7# in bar
P1= P1*10**5# in N/m**2
V1 = 1.6# in m**3
V2 = 8# in m**3
P2 = (P1 * (V1)**(Gamma))/((V2)**(Gamma)) # in bar
W1 = (P1*V1-P2*V2)/(Gamma-1) # work done by the gas during isentropic expansion in J
Rho = V2/V1#
W2 = P1*V1*(log(Rho)) # work done by the gas during isothermal expansion in J
del_W = W2-W1# in J
del_W = del_W*10**-3 # in kJ
print "Difference between the work done during isentropic and isothemal expansion = %0.0f kJ " %del_W
```

In [21]:

```
# Given data
P1 = 1# in bar
V1 = 400# in cm**3
V2 = 80# in Cm**3
T1 = 110# in degree C
T1 = T1 + 273# in K
Gamma = 1.3#
P2 = P1*((V1/V2)**(Gamma)) # in bar
print "The pressure = %0.1f bar " %P2
T2 = T1 * ((P2*V2)/(P1*V1)) # in K
T2 = int(T2-273)#in degree C
print "The temperature = %0.0f degree C " %T2
T2 = T2 + 273# in K
m = 1#
C_V = 0.75#
del_U = m*C_V*(T2-T1) # in kJ
print "Change in internal energy = %0.2f kJ " %del_U
P1= P1*10**5# in N/m**2
P2= P2*10**5# in N/m**2
V1= V1*10**-3# in litre
V2= V2*10**-3# in litre
W = (P1*V1-P2*V2)/(Gamma-1) # in J
W = abs(W * 10**-3) # in kJ
print "Work done = %0.2f kJ " %W
P3 = 40*10**5# in N/m**2
T3 = (P3/P2) * T2# in K
T3 = T3 - 273# in degree C
print "Temperature of gas = %0.0f degree C " %T3
```

In [22]:

```
# Given data
C_P = 1.068# in kJ/kg-K
C_V = 0.775#in kJ/kg-K
R = C_P-C_V# in kJ/kg-K
R= R*10**3# in J/kg-K
P1 = 12# in bar
P1= P1*10**5# in N/m**2
V1 = 0.15#in m**3
V2= 0.28# in m**3
m = 1# in kg
T1 = (P1*V1)/(R* m) # in K
T2 = (T1 * (V2/V1)) # in K
print "Temperature at the end of Constant pressure = %0.3f °C " %(T2-273)
W = P1* (V2-V1) # in J
W = W * 10**-3# in kJ
Gamma = 1.38
V3 = 1.5# in m**3
T3 = T2/((V3/V2)**(Gamma-1)) # in K
T3 = (T3 - 273)# in degree C
print "Temperature at the end of Isentropic = %0.0f °C " %T3
T3 = T3 + 273# in K
W1 = m *C_V*(T2-T3) # work done during isentropic expansion in kJ
W2 = W+W1# in kJ
print "Total Work done = %0.2f kJ " %W2
```

In [23]:

```
from scipy.integrate import quad
# Given data
C_P = 1.005# in kJ/kg-K
C_V = 0.718# in kJ/kg-K
R = C_P-C_V# in kJ/kg-K
P1 = 20#in bar
P2 = 12# in bar
T1 = 200#in degree C
T1 = T1 + 273# in K
T2 = 125#in degree c
T2 = T2 + 273# in K
V1 = (R*10**3*T1)/(P1*10**5) # in m**3
V2 = (R*10**3*T2)/(P2*10**5) # in m**3
def integrand(V):
return -293*V+40
ans, err = quad(integrand, 0.0679,0.0952)
W = 10**5 * ans# in Joules
W = round(W * 10**-3) # in kJ
print "Work done = %0.0f kJ " %W
m = 1# in kg
del_U = m*C_V*(T2-T1) # change in internal energy in kJ
print "Change in internal energy = %0.2f kJ " %del_U
print "Negative sign indicates that there is decrease in internal energy of the gas. "
C_Enthalpy = m*C_P*(T2-T1) # change in enthalpy in kJ
print "The change in enthalpy = %0.1f kJ" %C_Enthalpy
print "Negative sign indicates that there is decrease in enthalpy of the gas"
Q = W+ del_U# in kJ
print "Heat transfer = %0.2f kJ " %Q
print "Negative sign indicates that the heat is rejected by the air"
```

In [40]:

```
from math import log
import math
# Given data
P1 = 14# in bar
P3 = 2.222# in bar
V3byV1 = P1/P3#
P2 = 1.05# in bar
Gamma = log(P1/P2)/log(V3byV1)
C_P = 1.005# in kJ/kg-K
C_V = C_P/Gamma# in kJ/kg-K
T3 = 343# in degree C
T3 = T3 + 273# in K
T2 = math.ceil(T3*P2)/P3# in K
m = 0.5# in kg
del_U = m*C_V*(T2-T3) # in kJ
print "Change in internal energy = %0.3f kJ " %del_U
print "i.e. there is a loss of",round(abs(del_U),3),"kJ of internal energy"
```

In [25]:

```
# Given data
R = 0.26# in kJ/kg-K
R = R * 10**3# in J/kg-K
Gamma = 1.4#
P1 = 3.1# MN/m**2
P1 = P1 * 10**6# N/m**2
P2 = 1.7# in MN/m**2
P2 = P2 * 10**6# in N/m**2
V1 = 500# in cm**3
T = 18# in degree C
T = T + 273# in K
T2 = 15# in degree C
T2 = T2 + 273# in K
m = (P1*V1)/(R*T)*10**-3# in kg
m_desh = (P2*V1)/(R*T2)*10**-3#in kg
M = m-m_desh# in kg
print "The mass of oxygen = %0.2f kg " %M
R = R * 10**-3# in kJ/kg-K
C_v = R/(Gamma-1) # in kJ/kg-K
Q = m_desh*C_v * (T-T2) # in kJ
print "Heat transfered = %0.3f kJ " %Q
```

In [26]:

```
# Given data
P1 = 1 * 10**5# in N/m**2
V1 = 0.1# in m**3
V2 = 0.01# in m**3
T1 = 90# in degree C
T1 = T1 +273# in K
R = 0.287# in kJ/kg-K
R = R *10**3#
C_v = 0.717# in kJ/kg-K
C_P = 1.005# in kJ/kg-K
m = (P1 * V1)/(R*T1) # in kg
Gamma = 1.4#
T2 = T1 * ((V1/V2)**(Gamma - 1)) # in K
del_U = m*C_v*(T1-T2) # in kJ
print "The change in internal energy = %0.2f kJ" %del_U
del_E = m * C_P*(T2-T1) # in kJ
print "The change in enthalpy = %0.2f kJ" %del_E
U2 = m*C_v*T2#Internal energy at 2 in kJ
T= 473# temp. of entering air
E = V1*C_P*T#Enthalpy of entering air in kJ
# U3= (m+V1)*C_v*T3 # (internal energy at 3)
# U3= U2+E
T3 = (E+U2)/( (m+V1)*C_v ) # in K
print "Temperature = %0.0f K" %T3
m=m+.1#
P3 =m* R*T3/V2# in N/m**2
print "The pressure = %0.3f MN/m**2 " %(P3*10**-6)
# Note: There is a calculation error to evaluating the value of P3. So the answer in the book of P3 is wrong.
```

In [27]:

```
# Given data
T= 60+273# in K
T2= 25+273# in K
P1=3.5*10**6# in Pa
P2=1.7*10**6# in Pa
Gamma=0.4# value of Cp-Cv
m1=1# (assumed value)
# R= P1*V/(m*T) (i)
# R= P2*V/((m-m1)*T2) (ii)
# From eq(i) and (ii)
m= m1*P1*T2/(P1*T2-P2*T)
# U= m*Cv*T and U1= (m-m1)*Cv*T2+m1*Cv*T1
# U-U1= P1*V1= m1*R*T1 or
# m1*R*T1= m*Cv*T-[(m-m1)*Cv*T2+m1*Cv*T1]
T1= (m*T-(m-m1)*T2)/(m1*Gamma+m1) # in K
print "The temperature of gas in the cylinder = %0.2f °C" %(T1-273)
```

In [28]:

```
# Given data
U=180# energy received by system in kJ
RH= 200# rejected heat by system in kJ
RcHeat= 50# received heat by system in kJ
W= U-RH+RcHeat# in kJ
U1 = 0# in kJ
U2= U+U1# in kJ
U3 = RcHeat-RH+U2# in kJ
print "Internal energy = %0.0f kJ " %U3
```

In [41]:

```
from math import log
# Given data
C_P = 1.045# in kJ/kg-K
Q = 100# in kJ
del_T = Q/C_P# in degree C
T1 = 25# in degree C
T1 = T1 + 273# in K
T = 0# in degree C
T = T + 273# in K
T2 = T1 + del_T# in K
del_Phi = C_P * (log(T2/T1)) # in kJ/kg-K
print "The change in entropy in the process = %0.3f kJ/kg-K " %del_Phi
ini_entropy = C_P * (log(T1/T)) # initial entropy in kJ/kg-K
print "The initial entropy = %0.3f kJ/kg-K " %ini_entropy
```