In: Computer Science
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.
"""
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