Question: Write a program in Python that first asks the user for the names of input and output files. For each line in the input file,
Write a program in Python that first asks the user for the names of input and output files. For each line in the input file, the program should write to the output file the number of times the line contains "the" or "The" followed by the line itself as it is. A sample input file (PA5_input.txt) and its corresponding output file (PA5_output.txt) are posted. Note: The program will count all occurrences of "the" or "The" including when they are part of another word, for example, "these".
Hint: Use the string's count() function. If you find that your program prints an extra line for every line then you may need to remove the newline character from each line, for example, by using the string's rstrip() function.
The program will run like this:
>>> import PA5_solution Give the name of the input file: PA5_input.txt Give the name of the output file: PA5_output.txt Output has been written to PA5_output.txt >>>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
