I cannot upload the needed text files to this question for your benefit of double checking your solution, but I need help on this multi part question. Thanks!
Write a Python program that will open the ‘steam.csv’ file. Your program should load the data as col- umns corresponding to the variable names located in the first row (You can hard code this – i.e open the file and use the names in the first row as variable names). You should neglect the second row since these are reserved for units. Load each column of numerical data into a tuple corresponding the variable name. Name your file Lab9a.py.
Write a new program that will prompt the user for a file name. If the file exists, the program should open the file and load the data (you can use your code from above). Prompt the user if they would like to print the data to the screen or if they would like to print a particular column of data (as defined by the varia- ble) to the screen. The prompt should look like a menu below. Name your file Lab9b.py.
What would you like to do?
1) Print all data to Screen
2) Print a particular variable
if menu item 2 is chosen, display the following:
a) Temperature
b) Pressure
c) Specific Volume – liquid (vf)
d) Specific Volume – vapor (vg)
e) Internal Energy – liquid (uf)
f) Internal Energy – vapor (ug)
g) Enthalpy – liquid (hf)
h) Latent Heat of Vaporization (hfg)
i) Enthalpy – vapor (hg)
j) Entropy – liquid (sf)
k) Change in Entropy (sfg)
l) Entropy – vapor (sg)
Code Lab9a.py
import csv
lis=[]
#Hard coding from csv file
Temperature=[]
Pressure=[]
vf=[]
vg=[]
uf=[]
ug=[]
hf=[]
hfg=[]
hg=[]
sf=[]
sfg=[]
sg=[]
with open('steam.csv', 'r') as file:
reader = csv.reader(file)
for i in reader:
lis.append(i)
row=len(lis)
col=len(lis[0])
for i in range(row-2):
#hardcoding
Temperature.append(int(lis[i+2][0]))
Pressure.append(int(lis[i+2][1]))
vf.append(int(lis[i+2][2]))
vg.append(int(lis[i+2][3]))
uf.append(int(lis[i+2][4]))
ug.append(int(lis[i+2][5]))
hf.append(int(lis[i+2][6]))
hfg.append(int(lis[i+2][7]))
hg.append(int(lis[i+2][8]))
sf.append(int(lis[i+2][9]))
sfg.append(int(lis[i+2][10]))
sg.append(int(lis[i+2][11]))
TemperatureT=tuple(Temperature)
PressureT=tuple(Pressure)
vfT=tuple(vf)
vgT=tuple(vg)
ufT=tuple(uf)
ugT=tuple(ug)
hfT=tuple(hf)
hfgT=tuple(hfg)
hgT=tuple(hg)
sfT=tuple(sf)
sfgT=tuple(sfg)
sgT=tuple(sg)
Code Lab9b.py
import csv
lis=[]
#Hard coding from csv file
Temperature=[]
Pressure=[]
vf=[]
vg=[]
uf=[]
ug=[]
hf=[]
hfg=[]
hg=[]
sf=[]
sfg=[]
sg=[]
try:
filename=input("Please enter a file name ")
with open(filename, 'r') as file:
reader = csv.reader(file)
for i in reader:
lis.append(i)
except:
print("Error while opening file check your file name if it exists")
exit();
row=len(lis)
col=len(lis[0])
for i in range(row-2):
#hardcoding
Temperature.append(int(lis[i+2][0]))
Pressure.append(int(lis[i+2][1]))
vf.append(int(lis[i+2][2]))
vg.append(int(lis[i+2][3]))
uf.append(int(lis[i+2][4]))
ug.append(int(lis[i+2][5]))
hf.append(int(lis[i+2][6]))
hfg.append(int(lis[i+2][7]))
hg.append(int(lis[i+2][8]))
sf.append(int(lis[i+2][9]))
sfg.append(int(lis[i+2][10]))
sg.append(int(lis[i+2][11]))
TemperatureT=tuple(Temperature)
PressureT=tuple(Pressure)
vfT=tuple(vf)
vgT=tuple(vg)
ufT=tuple(uf)
ugT=tuple(ug)
hfT=tuple(hf)
hfgT=tuple(hfg)
hgT=tuple(hg)
sfT=tuple(sf)
sfgT=tuple(sfg)
sgT=tuple(sg)
print("What would you like to do?")
print("1) Print all data to Screen")
print("2) Print a particular variable")
inp=int(input())
if(inp==2):
print('''a) Temperature
b) Pressure
c) Specific Volume – liquid (vf)
d) Specific Volume – vapor (vg)
e) Internal Energy – liquid (uf)
f) Internal Energy – vapor (ug)
g) Enthalpy – liquid (hf)
h) Latent Heat of Vaporization (hfg)
i) Enthalpy – vapor (hg)
j) Entropy – liquid (sf)
k) Change in Entropy (sfg)
l) Entropy – vapor (sg)''')
print("Enter your choice a-l")
inp2=input()
if(inp2=="a"):
print("Temperature ",TemperatureT)
elif(inp2=="b"):
print("Pressure ",PressureT)
elif(inp2=="c"):
print("Specific Volume – liquid ",vfT)
elif(inp2=="d"):
print("Specific Volume – vapor ",vgT)
elif(inp2=="e"):
print("Internal Energy – liquid ",ufT)
elif(inp2=="f"):
print("Internal Energy – vapor ",ugT)
elif(inp2=="g"):
print("Enthalpy – liquid ",hfT)
elif(inp2=="h"):
print("Latent Heat of Vaporization ",hfgT)
elif(inp2=="i"):
print("Enthalpy – vapor ",hgT)
elif(inp2=="j"):
print("Entropy – liquid ",sfT)
elif(inp2=="k"):
print("Change in Entropy ",sfgT)
elif(inp2=="l"):
print("Entropy – vapor ",sgT)
else:
print("Invalid Input")
elif(inp==1):
for i in lis:
for j in i:
print(j,end=" ")
print()
else:
print("Invalid Input")
Dummy Output Lab9b.py:
Please enter a file name steam.csv
What would you like to do?
1) Print all data to Screen
2) Print a particular variable
2
a) Temperature
b) Pressure
c) Specific Volume – liquid (vf)
d) Specific Volume – vapor (vg)
e) Internal Energy – liquid (uf)
f) Internal Energy – vapor (ug)
g) Enthalpy – liquid (hf)
h) Latent Heat of Vaporization (hfg)
i) Enthalpy – vapor (hg)
j) Entropy – liquid (sf)
k) Change in Entropy (sfg)
l) Entropy – vapor (sg)
Enter your choice a-l
f
Internal Energy – vapor (30, 30, 30)
Get Answers For Free
Most questions answered within 1 hours.