Pythong Program 4 should first tell users that this is a word analysis software. For any…

Pythong Program 4 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. 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. Then the program reads the contents of the
text file and create a dictionary in which the
key-value pairs are described as follows:

Key. The key are the individual words found in
the file.
Value. Each 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 output, 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.
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 files, Kennedy.txt and
romeo.txt. The output file of the Kennedy_index.txt,
Kennedy_index_B.txt, Kennedy_index_C.txt, for input file
“kennedy.txt” and the output file romeo_index.txt,
romeo_index_B.txt, romeo_index_C.txt, for input file romeo.txt have
been posted for your reference.
Remember the output file name of your program is
words_index.txt.

KENNEDY.TXT
We observe today not a victory
of party but a celebration
of freedom symbolizing an end
as well as a beginning
signifying renewal as well
as change
ROMEO.TXT
But soft what light through yonder window
breaks
It is the east and Juliet is the sun
Arise fair sun and kill the envious moon
Who is already sick and pale with grief