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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education