Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Overview 1. This is a demonstration of File 10 Description Read from an input file, reverse each line of the input file and write these
Overview 1. This is a demonstration of File 10 Description Read from an input file, reverse each line of the input file and write these reversed lines to the output file. Provided input file: A single input file named myinput.txt is provided that contains a few lines of text. Purple cow jumped over the moon Provided output file: A single output file named myoutput.txt is provided that is initially empty. Objectives Write the following in main.py: 1. Open the myinput.txt file in "read-only" form. 2. Open the my out put. txt file in "write only" form. 3. Write your program so it reads one line at a time, from the file named "myinput.txt". The line should be stripped ( that means you need to remove the carriage return by using strip)). 4. Once the line is cleaned up from carriage return, you need to iterate through one character at a time and reverse the line. (Hint: Use a new string variable and add each character to the left of the new string variable, that will reverse the line) 5. After processing the line, write this new string variable that contains the reversed line to the output file named 'myoutput.txt" 6. Include a print statement to show to the user what we should have in our output file. 7. Close both files. Sample Output to the File woc elpru depmuj !noom eht revo Sample Output to the User Purple cow ==> woc elpruP jumped ==> depmuj ==> !noom eht revo over the moon! Note: You will lose points if you do not correctly work with the files. If you decide to just use a print statement to display the output, without using file input/output, and pass the test case with 100%, you will eventually lose points. This program will be checked after the deadline. In short, do not try to cheat the system by simply displaying the reversed text
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started