Answered step by step
Verified Expert Solution
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 should first tell users that this is a word analysis software. For any usergiven 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 tryexcept for invalid user input. The program reads the contents of the text file, stripremove newline and punctuation characters, and then create a dictionary in which the keyvalue 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 wordsindex.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 functions:
a function gets the input file name from user
a function creates the dictionary
Bonus Points a function to write the top words by the number they appear in the input file by descending order with the number to the output file wordsindex.txt
a function to write the alphabetical listing of the words with their line numbers to the output file wordsindex.txt
the main function which the program starts here.
Looking to seeing everyone to submit a welldone program! Here are some tips:
DocumentsComments of your program Never more
Testing your program by the given two sample files, input file romeotxt and output file romeoindex.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 Most Common Words:
and:
the :
sun:
is:
yonder:
The alphabetical listing of the words:
Arise :
But :
It :
Juliet :
Who :
already :
and :
breaks :
east :
envious :
fair :
grief :
is :
kill :
light :
moon :
pale :
sick :
soft :
sun :
the :
through :
what :
window :
with :
yonder :
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started