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: Prompt the user for the filename Open the file in "read-only" form. Open the myoutput.txt file in "write only" form. Write your program so it reads one line at a time, from the file named "myinput.txt". Each line should be stripped (that means you need to remove the carriage return by using strip() ). Once the line is cleaned up, you need to remove all spaces within the line. (Hint: Use the string replace function). 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. Include a print statement to show to the user what we should have in our output file. Repeat steps 4-7 for all lines in the input file. 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
In Python
A single output file named myoutput.txt is provided that is initially empty.
Description
Create a
You must follow these steps:
- Prompt the user for the filename
- Open the file in "read-only" form.
- Open the myoutput.txt file in "write only" form.
- Write your program so it reads one line at a time, from the file named "myinput.txt".
- Each line should be stripped (that means you need to remove the carriage return by using strip() ).
- Once the line is cleaned up, you need to remove all spaces within the line. (Hint: Use the string replace function).
- 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.
- Include a print statement to show to the user what we should have in our output file.
- Repeat steps 4-7 for all lines in the input file.
- 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
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images