Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Python supports the use of data files. In Python there are different modes that allow a user to create, write, append, read, and update

1) Python supports the use of data files. In Python there are different modes that allow a user to create, write, append, read, and update date files. Table 1 shows the various file modes in Python.

Make a Python program that creates a user interface (menu) which allows the user to choose an option from the followings menu then perform the required task accordingly. The menu should have the following options:

1. Writing text to a file: Write the 6 to 8 lines of text into a file named "assignment2.txt". You can use special characters such as to separate lines.

2. Read Data from a file: reads (retrieve) the data from the file "assignment2.txt" and print it on the screen in the same format as it was input (i.e., same number of lines). Make sure

Table 1: Python File modes

Mode Description

'r' Opens a file for reading.

'w' Open a file for writing. If file does not exist, it creates a

new file. If file exists it truncates the file.

'a' Open a file in append mode. If file does not exist, it

creates a new file.

'+' Open a file for reading and writing (updating)

the file already exist and it is not empty, otherwise warn the user that the file doesn't exist or it is empty.

3. Search for string and calculate the number of occurrences: you should search for a certain word that you specify from the text. If the word doesn't exist, it should report to the user "the word doesn't exist" and asks the user to enter another word.

4. Quit the program: allows the user to quit the execution of the program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions