In [1]:

```
#initialization of variables
m=1 # mass in kg
x=20.0/100.0 #quality of steam
P=200 #constant pressure in kPa
T1=100 #temperature intitial in degree centigrade
T2=400 #temperature final in degree centigrade
# first we find initial volume v1 and final volume v2
# using table C.2
vf=0.001061 # specific volume of saturated liquid in m^3 per kg
vg=0.8857 # specific volume of saturated vapour in m^3 per kg
v1=vf+x*(vg-vf);
v2=1.549 # specific volume of steam in m^3 per kg at T2=400*C and P2=0.2MPa
# now calculate work
W=m*P*(v2-v1); # work done in constant pressure process
#result
print "Work done is",round(W,2)," kJ" # work is in kJ as pressure was in kPa
```

In [11]:

```
import math
#initialization of variables
D=110.0/1000.0 # diameter of cylinder in m
V1=100e-6 # initial volume@ state 1 in m^3
T1=60.0 # initial temp @ state 1 in *C
T2=200.0 # final temo @ state 2 in *C
M=50 # weight of piston in kg
g=9.81 # gravitational accleration in m/sec^2
Patm=100000 # atmospheric pressure in Pa
A=math.pi*(D**2)/4 # area of piston in m^2
# BALANCING THE FORCES To GET PRESSURE P
# M.g=P.A-Patm
P=Patm+(M*g/A) # atm pressure is added to get absolute pressure
v1=0.001017 # specific volume at 60*C and 0.15Mpa pressure
m=V1/v1; # mass of water in kg
# find volume at state 2
v2=1.444 # specific volume of steam at 200*C and 0.15 MPa
V2=m*v2 # final volume in m^3
W=P*(V2-V1)/1000; # work done divided by 1000 to get in kJ
# result
print "The work done is",round(W,1)," kJ"
```

In [28]:

```
#initialization of variables
P1=200 # initial pressure in kPa
V1=2 # initial volume in m^3
P2=100 # final pressure in kPa
C=P1*V1 # isothermal process i.e P.V=constant
# find final volume
V2=P1*V1/P2 # final volume by P1.V1=P2.V2
from scipy.integrate import quad
def integrand(v,C):
return C/v
W, err =quad(integrand, V1, V2,C ) # itegrating over volume to get work
# result
print "The Work done by gas is",int(W)," kJ" # answer is approximated in textbook
```

In [33]:

```
# initialization of variables
M=100 # mass in kg
d=3 # depth by which mass drops in m
V=0.002 # increased volume in m^3
g=9.8 # gravitational accleration in m/sec^2
Pgauge=100*1000 # gauge pressure in N/m
Patm =100*1000 # atmospheric pressure in N/m
P=Pgauge+Patm # to get absolute pressure
# calculate work done by paddle wheel
Wpaddlewheel=(-M*g*d) # work is negative as it is done on the system
# calculate work done on piston it
Wboundary=P*V # area mulitiplied by height is volume thus W=P.V
#net work
Wnet=Wpaddlewheel+Wboundary; # Work in joule as SI units are used
print "The Net Work done is ",round(Wnet)," J"
```

In [35]:

```
import math
# initialization of variables
T=100 # torque of shaft in N.m
N=3000 # rotation speed in rpm
omega=(N*2*math.pi/60) # angular velocity in rad/sec
# calculation of power
Wdot=(T*omega); # power is work done per unit time
print "Power transmitted is",round(Wdot/746,1)," hp" # divided by 746 to convert W into hp
#answer is approximated in textbook
```

In [43]:

```
import math
# initialization of variables
D=10.0/100 # diameter of cylinder in m
d=50.0/1000 # compression in spring in m
Patm=100000 # atmospheric pressure in Pa
K=10.0*1000 # spring constant converted in N/m
w=50*9.81 # weight of piston in Newton =mass*gravitational acceleration
# find the initial pressure in cylinder by force balance
A=(math.pi*D**2)/4; # area of piston
P1=((Patm*A)+w)/A; # balancing forces on piston P1.A=Patm.A+W
# work done by air to raise the piston for 50mm if spring not present
Wgas=P1*A*d; # pressure*area= force and Work = Force* displacement
# work done on spring to compress
Wspring=(K*d**2)/2; # Work in j
# now total work done by air is sum of two works
Wnet=Wgas+Wspring; # Work in j
# result
print "The net work done by air is",round(Wnet,1)," J"
```

In [45]:

```
# variable initialization
d=2 # distance travelled by weight in m
m=50 # mass of weight in kg
g=9.8 # gravitaional acceleration in m/sec^2
# calculation of work in non-quasiequilibrium process
W=m*g*d; # work in joules
# the work done must be transferred as heat
Q=W;
print "The heat that must transfer is ",int(Q)," Joules"
```