import math
# Variables
R = 8.314; #universal gas constant in J/molK
t1 = 300.; #initial temperature of gas in K
p1 = 0.1; #initial pressure of the gas in MPa
p2 = 0.5; #pressure of gas after heating in MPa
p3 = 0.1; #pressure of gas after expansion in MPa
n = 1.; #number of moles of gas in mole
# Calculations
w1 = 0*n; # Calculations of work done by the gas during heating in kJ (since dv = 0)
t2 = t1*(p2/p1); # Calculations of temperature of gas after heating in K
t3 = t2; # Calculations of temperature of gas after expansion in K (constant temperature expansion)
volume2 = p2/p3; # Calculations of ratio of volume of gas after expansion to the volume of gas after heating (no unit)
w2 = (R*t2*math.log(volume2)*n)/1000
volume3 = t3/t1;
w3 = (R*t1*(1-volume3)*n)/1000
work_net = w1+w2+w3; # Calculations of net work done by the gas for the process in kJ
# Results
print ' Work done during heating process:Work from 1-2 = %d kJ '%(w1);
print ' Work done during constant temperature expansion: Work from 2-3 = %.3f kJ '%(w2);
print ' Work done during constant pressure compression: Work from 3-1 = %.3f kJ '%(w3);
print ' Net work done by the gas during the process = %.3f kJ '%(work_net);
# Variables
v1 = 0.1; #volume of gas initially present in the cylinder in m**3
p1 = 0.1; #initial pressure of gas in MPa
p_atm = 0.1; #atmospheric pressure acting on the piston in MPa
v2 = 0.3; #volume of gas after heating in m**3
p2 = 0.6; #pressure of gas after heating in MPa
# Calculations
work = ((p1+p2)*(v2-v1)*10**6)/(2*1000); # Calculations of work done by the gas in kJ
# Results
print ' The work done by the gas = %d kJ'%(work);