In Python A single output file named myoutput.txt is provided that is initially empty. Description Create a program to prompt the user for an input text file, read each line of the input file,...


In Python


A single output file named myoutput.txt is provided that is initially empty.


Description


Create a program to prompt the user for an input text file, read each line of the input file, determine if the text on the line is a palindrome, and write "palindrome" or "not a palindrome" to the output file depending on the input. Remember that a palindrome is a word or a phrase that is the same when read both forward and backward. In this program, you need to ignore spaces when determining if a phrase is a palindrome. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces).


You must follow these steps:



  1. Prompt the user for the filename

  2. Open the file in "read-only" form.

  3. Open the myoutput.txt file in "write only" form.

  4. Write your program so it reads one line at a time, from the file named "myinput.txt".

  5. Each line should be stripped (that means you need to remove the carriage return by using strip() ).

  6. Once the line is cleaned up, you need to remove all spaces within the line. (Hint: Use the string replace function).

  7. After processing the line, check if it is a palindrome. If the line is a palindrome, write "palindrome" to the output file named "myoutput.txt". If it is not a palindrome, write "not a palindrome" to the output file.

  8. Include a print statement to show to the user what we should have in our output file.

  9. Repeat steps 4-7 for all lines in the input file.

  10. Close both input and output files.


Sample Output to the File from the Provided Input File


palindrome


palindrome


not a palindrome


palindrome


not a palindrome


palindrome


Sample Output to the User from the Provided Input File


bob ==> palindrome


sees ==> palindrome


over the moon ==> not a palindrome


never odd or even ==> palindrome


statistics ==> not a palindrome


dr awkward ==> palindrome

Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here