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
I am looking for PYTHON code that will display the following: Code a menu-driven application that...
I am looking for PYTHON code that will display the following: Code a menu-driven application that does the following: The user can enter data for a product name, product code, and unit price. An example might be 'Breaburn Apples', 'BAP'. 1.99. After entering the data, it is appended (note I said 'appended') as a single line of text to a text file. Each line of text in the file should represent a single product. There is an option to display...
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...
The project CreateDirectoriesDemo is included with the files for this chapter as a zipped file. rewrite...
The project CreateDirectoriesDemo is included with the files for this chapter as a zipped file. rewrite the program so that it asks the user for the location where the new directories are to be created, and then asks the user to enter, one at a time, the relative path names of the directories it should create. Amended additional details to the above abstraction of the requirements. The application should be multiplatform adaptive. This means that it should work on an...
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...
n this lab, you use what you have learned about parallel arrays to complete a partially...
n this lab, you use what you have learned about parallel arrays to complete a partially completed C++ program. The program should: Either print the name and price for a coffee add-in from the Jumpin’ Jive Coffee Shop Or it should print the message Sorry, we do not carry that. Read the problem description carefully before you begin. The file provided for this lab includes the necessary variable declarations and input statements. You need to write the part of the...