Question

I cannot upload the needed text files to this question for your benefit of double checking...

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. 1) Print all data to Screen

  2. 2) Print a particular variable

if menu item 2 is chosen, display the following:

  1. a) Temperature

  2. b) Pressure

  3. c) Specific Volume – liquid (vf)

  4. d) Specific Volume – vapor (vg)

  5. e) Internal Energy – liquid (uf)

  6. f) Internal Energy – vapor (ug)

  7. g) Enthalpy – liquid (hf)

  8. h) Latent Heat of Vaporization (hfg)

  9. i) Enthalpy – vapor (hg)

  10. j) Entropy – liquid (sf)

  1. k) Change in Entropy (sfg)

  2. l) Entropy – vapor (sg)

Homework Answers

Answer #1

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)


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
I need python code for this. Write a program that inputs a text file. The program...
I need python code for this. Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase words should take precedence over lowercase words. For example, 'Z' comes before 'a'. The input file can contain one or more sentences, or be a multiline list of words. An example input file is shown below: example.txt the quick brown fox jumps over the lazy dog An example of the program's output...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
Please provide commenting of code so I can understand how to solve this problem. Please provide...
Please provide commenting of code so I can understand how to solve this problem. Please provide text files. Using C++ Write a program that reads a given file, and then outputs the contents of it to another file. It should also print out the number of lines and the number of times each alphabetic character appears (regardless of case) in the input file at the end of the output file. It should prompt the user for the input and output...
Question (excel) 1. Add a worksheet to the file and call it Output. 2. In the...
Question (excel) 1. Add a worksheet to the file and call it Output. 2. In the Output sheet: a. enter first name in cell A1.     b. enter last name in cell B1. 3. Record a macro. Call your macro CIS308Exam3. Within your macro, do the following:      a. In cell C1, use a formula to concatenate A1 and B1 with a space in between     b. Stop recording. 4. Open your macro in Visual Basic edit mode. Copy your...
An advantage of programming is the ability to perform millions of calculations and dump it to...
An advantage of programming is the ability to perform millions of calculations and dump it to a file for plotting. This can be extremely useful for engineers if they are simulating or characterizing a system. Below you will calculate data, write it to a file, and plot the contents in excel. a) Create a csv file for writing. This can be done by creating a file with the open method as we have done in class but with a *.csv...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept...
Assignment Overview This programming exercise introduces generics and interfaces. The students must create methods that accept generic parameters and perform operation on them. Deliverables A listing of the fully commented, working source code of the Java program Test data for the code A screen shot of the application in execution Step 1 Create a new project. Name it "Assignment_2_1". Step 2 Build a solution. Write the Java source code necessary to build a solution for the problem below:You have just...
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....
Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please. (Use your own words, don't copy and paste) Write a Java program that: Asks the user to enter his/her first name and ID. Prints the user's first name and ID in reverse order with a space between them recursively. Important notes: You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT