In: Computer Science
Top-Down Design of a Program in PYTHON
Following the process described in the lecture, you should, as a team, perform a top-down design for a program. Then, construct code for the program.
Open the Excel file entitled “Lab8-data.xlsx”. This document lists thermodynamic properties of liquid water at varying temperatures and at two different pressures. The properties listed are as follows:
It is common to use linear interpolation for temperature values not listed. So, for example, if you need the properties at T=25 ℃ , you could interpolate between the property values listed for T=20 ℃ and T=40 ℃ as a good estimate.
For your program, hard-code the temperature and property values for P = 5 MPa as lists for temperatures from T=0 ℃ to at least T=100 ℃ . Have the user enter a temperature in that range from the keyboard. Your program should find the two values of temperature that bracket the user’s value, then perform linear interpolation for all four properties. The results should be formatted and printed to the screen based on the example output shown below. Print the specific volume, specific internal energy, specific enthalpy, and specific entropy to 7, 2, 2, and 4 decimal places, respectively.
Example output (using input 50):
Enter a temperature between 0 and 260 C: 50
Properties at 50.0 deg C are:
Specific volume (m^3/kg): 0.0010103
Specific internal energy (kJ/kg): 208.60
Specific enthalpy (kJ/kg): 213.66
Specific entropy (kJ/kgK): 0.6996
def interpolate(temp2,temp1,val2,val1,temp_inp):
return val1+ ((temp_inp-temp1)*(val2-val1)/(temp2-temp1))
Data = [[10,1,2,3,4],[20,3,5,7,0],[70,8,12,45,13],[100,34,67,92,12]] #You need to hardcode this from Lab8-data.xlsx in the format temperature,Specific volume, Specific internal energy, Specific enthalpy, Specific entropy
print("Enter temperature")
Data.sort(key = lambda x: x[1]) #sorting the list in ascending order of temperatute
inp = float(input())
for i,j in enumerate(Data):
if j>Data[0]:
c = i
break
result = []
print("Properties at "+str(inp)+" C are:-")
for i in range(1,5):
result.append(interpolate(Data[c][0],Data[c-1][0],Data[c][i],Data[c-1][i],inp))
print("Specific volume (m^3/kg): {0:.7f}".format(result[0]))
print("Specific internal energy (kJ/kg): {0:.2f}".format(result[1]))
print("Specific enthalpy (kJ/kg): {0:.2f}".format(result[2]))
print("Specific entropy (kJ/kgK): {0:.4f}".format(result[3]))
Let's take an example:-
Assume your Lab 8.xlsx looks like this
Temperate 10 20
specific internal energy 12 25
specific enthalpy 14 9
specific entropy 15 1
in the python code, you'll write
data = [[10,12,14,15,[20,25,9,1]]