I need help writing python code with following instructions. You will write a program that reads a data file. The data file contains ticket IDs and ticket prices. Your job is to read these tickets (and prices). find minimum, maximum and average ticket prices and output a report file. The report file should look exactly (or better than) the one attached (output.txt). Input: A31 149.99 B31 49.99 A41 179.99 F31 169.99 A35 179.99 A44 169.99 open "input.txt" file using open() function. let variable f refer to the opened file. 2) create a list of strings (let's call this lines) where each item in the list represent a line in the file. You can do that by calling read() method followed by a split method. lines = f.read().split("\n") on some systems, you may need to do: lines = f.read().split("\r\n") make sure to close the file afterwards. f.close() 3) initialize variables total (with which we will accumulate the sum of prices in the input file), priceMin (the lowest priced ticket, initialized to a large value, ex. 99999), priceMax (the highest priced ticket initialized to a small value. ex. 0). 4) create a for loop that goes over each line in lines list. for line in lines: 5) the line contains two pieces of information, the seat and then the price with a space character in between. So let's split the line with space character to separate the price from seat designation. cols = line.split(" ") 6) at this point, cols[0] is the seat designation, and cols[1] is the price of this ticket. We can ignore the seat designation -- all we need is the price. Remember that everything we read from the file is a string. In order to work with price we need to convert it to a number. price = float(cols[1]) 7) add price to total. 8) if price is larger than priceMax, set priceMax to price. 9) if price is smaller than priceMin, set priceMin to price. 10) Note that steps 5 to 9 are inside the for loop created at step 4. Once this loop runs, the total will be the sum of all ticket prices and priceMax and priceMin will contain the minimum and maximum prices. We can now output to output.txt, like this: f = open("output.txt", "w") f.write("*******************************************\n") f.write(" TICKET REPORT\n") f.write("*******************************************\n\n") f.write("There are " + str(len(lines)) + " tickets in the database.\n\n") f.write("Maximum Ticket price is $" + str(priceMax) + "\n") f.write("Minimum Ticket price is $" + str(priceMin) + "\n") f.write("Average Ticket price is $" + str(total / len(lines)) + "\n\n") f.write("Thank you for using our ticket system!\n\n") f.write("*******************************************\n") f.close()
Here is the answer....
Code snapshot:

Here is the ouptut:

Here is the input.txt

CODE:
f=open("input.txt",'r')
s=f.read()
lines=s.split("\n")
priceMax=0
priceMin=9999
total=0
for line in lines:
#print(line)
cols=line.split(" ")
price=(float)(cols[1])
total=total+price
if(price>priceMax):
priceMax=price
if(price<priceMin):
priceMin=price
f.close()
f=open("output.txt",'w')
f.write("*******************************************\n")
f.write(" TICKET REPORT\n")
f.write("*******************************************\n\n")
f.write("There are " + str(len(lines)) + " tickets in the
database.\n\n")
f.write("Maximum Ticket price is $" + str(priceMax) + "\n")
f.write("Minimum Ticket price is $" + str(priceMin) + "\n")
f.write("Average Ticket price is $" + str(total / len(lines)) +
"\n\n")
f.write("Thank you for using our ticket system!\n\n")
f.close()
print("File Created sucessfully")
input.txt:
A31 149.99
B31 49.99
A41 179.99
F31 169.99
A35 179.99
A44 169.99
If you have any doubts please COMMENT...
If you understand the answer please give THUMBS UP....
I need help writing python code with following instructions. You will write a program that reads...
Write a java program that reads a given data file called tickets that consists of tickets and the ticket prices. Your program should read the data and compute the find minimum, maximum and average ticket prices and output the report into a file called output.txt. The report file should look exactly (or better than) the one shown below. Your program should implement the Java ArrayList class, Java File I/O, and Java error handling exception. Below is the content of the...
I need help modifying this python code: a) I need to take 2 attributes of the data as int - (columns (3 & 5) of my data) b) I need to take 2 more attributes as floats -(columns 4&6 of my data) c) I need to take 1 attribute as string (column 16 of my data) How would I modify this code # # Initial version - "standard programming" # # Define a list for the data. The data structure...
I need help writing a program in python that reads from a file and performs matrix multiplication. the file has this format 1 4 2 1 1 1 1 1 1 2 2 3 3 4 4 which means : 1 #rows in A 4 #cols in A, rows in B 2 #cols in B Matrix A contents: 1 1 1 1 Matrix B contents: 1 1 2 2 3 3 4 4 i need to be able to read...
I need python help .. I need to know if a user were to input 3 commands to a program and run it such as specify: Usage: ./filemaker INPUTCOMMANDFILE OUTPUTFILE RECORDCOUNT (./filemaker is the program)( (INPUTCOOMANDFUILE= a text file that contains key words that need to be searched through then decided what to do ) (RECORDCOUNT= number) Given an input file that contains the following: That specifies the text, then the output, and the number of times to be repeated...
Python Error: Writing a program to complete the following: Prompt the user for the name of an input file. Open that file for input. (reading) Read the file using a "for line in a file" loop For each line, o print the line and compute and print the average word length for that line. Close the input file Sample output: MY CODE IS WRONG AND NEED HELP CORRECTING IT!!! ------------------------------------------------------------------------------------------------------------------------ DESIRED OUTPUT: Enter input file name: Seasons.txt Thirty days hath September...
Can you help us!! Thank you!
C++
Write a program that can be used by a small theater to sell tickets for performances. The program should display a screen that shows which seats are available and which are taken. Here is a list of tasks this program must perform • The theater's auditorium has 15 rows, with 30 seats in each row. A two dimensional array can be used to represent the seats. The seats array can be initialized with...
Instructions: Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13...
I need help in Python. This is a two step problem So I have the code down, but I am missing some requirements that I am stuck on. Also, I need help verifying the problem is correct.:) 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file...
below is my code please help me edit it so in the beginning it ask for Press any key to start Task n, where n is the task number (1, 2, or 3,4). I already wrote the code for the 4 task. Also please write it so when 1 code is finish running it return to the prompt where it ask to run another task #task 1 list1 = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','.',',','?'] morse = ['.-','-...','-.-.','-..','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..','-----','.----','..---','...--','....-','.....','-....','--...','---..','----.','.-.-.-','--..--','..--..'] inp = input("Enter original text : ")...
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...