please help me modify the sparse text program below so that instead of the letter 'e' being removed, the user is prompted for the letter to remove.

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

URGENT HELP NEEDED!

Hello, please help me modify the sparse text program below so that instead of the letter 'e' being removed, the user is prompted for the letter to remove.

 

 code in python below

---------------------------------------------------------------------

 

# Sparse Text Program

def createModifiedFile(input_file, output_file):

    """For text file input_file, creates a new version in file outputfile

    in which all instances of the letter 'e' are removed.

    """

    

    empty_str = ''

    num_total_chars = 0

    num_removals = 0

    

    for line in input_file:

        

        # save original line strength

        orig_line_length = len(line) - 1

        num_total_chars = num_total_chars + orig_line_length

        

        #remove all occurrances of letter 'e'

        modified_line = line.replace('e', empty_str).replace('E', empty_str)

        num_removals = num_removals + \

                        (orig_line_length - (len(modified_line) - 1))

        

        # simultaneouslt output line to screen and output file

        print(modified_line.strip('\n'))

        output_file.write(modified_line)

        

    return (num_total_chars, num_removals)

 

# --- main

 

# program welcome

 

print('This program will display the contents of a provided text file')

print('with all occurrences of the letter "e" removed. \n')

 

# open files for reading and writing 

file_name = input('Enter file name (including the file extension): ')

input_file = open(file_name, 'r')

new_file_name = 'e_' + file_name

output_file = open(new_file_name, 'w')

 

# create file with all letter e removed

print()

num_total_chars, num_removals = createModifiedFile(input_file, output_file)

 

# close current input and output files

input_file.close()

output_file.close()

 

# display percentage of characters removed

print()

print(num_removals, 'occurrences of the letter "e" removed')

print('Percentage of data lost:', int((num_removals / num_total_chars * 100), '%'))

print('Modified text in file', new_file_name)

Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
C-string
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
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