Question

In: Computer Science

Please Use Python 3.The Problem: Read the name of a file and then open it for...

Please Use Python 3.The Problem: Read the name of a file and then open it for reading. Read the name of another file and then open it for output. When the program completes, the output file must contain the lines in the input file, but in the reverse order. • Write the input, output, and the relationship between the input and output. • Develop the test data (A single test will be alright). Make the input file at least 3 lines long. I.E. Almost Honest Sweating Bullets Use the Man Use the Man Sweating Bullets Almost Honest • You need to figure out how to get the data in the reverse order. To get a handle on this, consider the problem statement and underline the verbs. “Read the name of a file and then open it for reading. Read the name of another file and then open it for output. When the program completes, the output file must contain the lines in the input file, but in the reverse order. “ Write the pseudo code for the steps. Figure out the order. Which step is hard? How will you go about doing the reversal? Think of what type of strategy that might work. Write your pseudo code here.

Solutions

Expert Solution

 

"""
Python program to read input file, reverse it aand write back to new output file
"""

def main():
inFileName = input('Enter input file name: ')
outFileName = input('Enter output file name: ')

inFile = open(inFileName, "r")
outFile = open(outFileName, 'w+')

lines = inFile.readlines()
lines.reverse()
lines = [l.strip() for l in lines]

for txt in lines:
outFile.write(txt + '\n')


if __name__ == '__main__':
main()

Input File

Output File


Related Solutions

Query the user for the name of a file. Open the file, read it, and count...
Query the user for the name of a file. Open the file, read it, and count and report the number of vowels found in the file. Using C++.
Python 3 8.5 Open the file mbox-short.txt and read it line by line. When you find...
Python 3 8.5 Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line: From [email protected] Sat Jan 5 09:14:16 2008 You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end. Hint: make sure not to include the lines that start...
PYTHON. Tasks: Create and test the openFileReadRobust() function to open file (for reading) whose name is...
PYTHON. Tasks: Create and test the openFileReadRobust() function to open file (for reading) whose name is provided from the standard input (keyboard) – the name is requested until it is correct Create and test the openFileWriteRobust () function to open file (for writing) whose name is provided from the standard input (keyboard) – the name is requested until is correct Extend the program to count number of characters, words and lines in a file as discussed in the classby including...
Step by step in python please Write a program this will read a file (prompt for...
Step by step in python please Write a program this will read a file (prompt for name) containing a series of numbers (one number per line), where each number represents the radii of different circles. Have your program output a file (prompt for name) containing a table listing: the number of the circle (the order in the file) the radius of the circle the circumference the area of the circle the diameter of the circle Use different functions to calculate...
Python program: Write a program that reads a text file named test_scores.txt to read the name...
Python program: Write a program that reads a text file named test_scores.txt to read the name of the student and his/her scores for 3 tests. The program should display class average for first test (average of scores of test 1) and average (average of 3 tests) for each student. Expected Output: ['John', '25', '26', '27'] ['Michael', '24', '28', '29'] ['Adelle', '23', '24', '20'] [['John', '25', '26', '27'], ['Michael', '24', '28', '29'], ['Adelle', '23', '24', '20']] Class average for test 1...
Write a program in python to read from a file the names and grades of a...
Write a program in python to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a getGrades() function that reads data from a file and stores it and returns it as a...
do not use these: {,},{} Python 3 APPL 276.75 15 A file named asset.txt consists of...
do not use these: {,},{} Python 3 APPL 276.75 15 A file named asset.txt consists of only the three lines above. They describe the unit cost and quantity of shares of Apple stock. Write statement that open the file, read the data and use it to print this exact output: My APPL stock is worth $4,151.25.
build a python program that will be performing: - Read a CSV file 'annual.csv' enterprise into...
build a python program that will be performing: - Read a CSV file 'annual.csv' enterprise into a data structure - Count the number of rows and columns - Determine if the data contains empty values - Replace the empty values by 'NA' for strings, '0' for decimals and '0.0' for floats - Transform all Upper case characters to Lower case characters - Transform all Lower case characters to Upper case characters - save back the 'repaired' array as csv -...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
fp=open("us-counties.2.txt","r") #open file for reading fout=open('Linsey.Prichard.County.Seats.Manipulated.txt','w') #file for writting states=[i.strip() for i in fp.readlines()] #read the...
fp=open("us-counties.2.txt","r") #open file for reading fout=open('Linsey.Prichard.County.Seats.Manipulated.txt','w') #file for writting states=[i.strip() for i in fp.readlines()] #read the lines try: #aplit values and write into file a,b=state.split(',') print(a,b) #write into file fout.write(a+":"+b+"\n")\ except Exception#if we dont have two names (For a line like KENTUCKY or OHIO, It continues) Pass evaluate Data. Manipulation.py] Traceback (most recent call last): File "C:/Users/Prichard/Data. Manipulation.py", line 10, in <module> except Exception#if we dont have two names (For a line like KENTUCKY or OHIO, It continues) Syntax Error:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT