Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 3 should first tell users that this is a word analysis software. For any user - given text file, the program will read, analyze,

Program 3 should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. If a word shows more than once at a line, the line number will be only recorded one time.
Ask a user to enter the name of a text file. Using try/except for invalid user input. The program reads the contents of the text file, strip/remove new-line and punctuation characters, and then create a dictionary in which the key-value pairs are described as follows:
Key. the words found in the file.
Value. Is a list that contains the line numbers in the file where the word (the key) is found. Be aware that a list may have only one element.
Once the dictionary has been built, the program should create another text file for otuput, named words_index.txt. Next, write the contents of the dictionary to the file as an alphabetical listing of the words that are stored as keys in the dictionary (sorting the keys), along with the line numbers where the words appear in the original file. Please see the sample file for your reference.
Your program must have at least 4 functions:
a function gets the input file name from user
a function creates the dictionary
(Bonus,10 Points) a function to write the top 6 words by the number they appear in the input file by descending order with the number to the output file words_index.txt.
a function to write the alphabetical listing of the words with their line numbers to the output file words_index.txt.
the main() function which the program starts here.
Looking to seeing everyone to submit a well-done program! Here are some tips:
Documents/Comments of your program (Never more)
Testing your program by the given two sample files, input file romeo.txt and output file romeo_index.txt.
Remember the output file name of your program is txt.
For this program, not running one (syntax error) will receive NO point.
Be sure each line of the code and its comment is your own.
The top 6 Most Common Words:
and: 3
the :2
sun: 2
is: 2
yonder: 1
The alphabetical listing of the words:
Arise : 3
But ,:1
It ,:2
Juliet ,:2
Who : 4
already : 4
and ,:2,3,4
breaks : 1
east :2
envious : 3
fair :3
grief ,:4
is ,:2,4
kill : 3
light ,:1
moon :3
pale : 4
sick ,:4
soft ,:1
sun ,:2,3
the ,:2,3
through : 1
what :1
window :1
with : 4
yonder ,:1
Romeo.txt = But $soft! What light through yonder window breaks?
It is the east and Juliet is ethe sun.
Arise fair sun and kill the envious moon, Who is already sick# and pale with grief!Text File to be analyzed: romeo.txt
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

=+What is our leadership style like?

Answered: 1 week ago

Question

=+What are our core competencies or competitive advantages?

Answered: 1 week ago