Question: 1 . Create a Python program file called Ch 0 9 - 2 _ Name.py . ( Replace Name with your initial of first name

1. Create a Python program file called Ch09-2_Name.py.(Replace Name with your initial of first name and first 5 letters of last name. If your last name is shorter than 5 letters, just use full last name, it doesn't have to be 5 letters. i.e. if your name is John Doe, your file name should be Ch09-2_JDoe.py)
2. Your program will take a file name from user and find out occurrences of words in the file. Case shouldn't matter, i.e. "the" and "The" should be counted as same word. Your output should list each word and occurrences of it in the file. Also, at the end, your program needs to print out number of different words in the file. You need to use Python Dictionary for this assignment. Make sure to exclude special characters. But words like "don't", "we'll" should be counted the way they are. Upper case and lower case letters should be treated the same, (i.e. "But" and "but" should be counted as same word)
Then output list of words and their occurrences in alphabetical order. One word per line with occurrences.
If user enters wrong information (wrong name of the file or non-existing file name), your program needs to display message and ask for correct input. Your program should not generate traceback message with any input.
Your program's output should be exactly same or very close to the sample output provided. Output should be formatted to match the sample output provided or points will be deducted (up to 8 points).
OUTPUT:
Please enter file name: abc.txt
File name abc.txt cannot be found
Please enter file name: abab
File name abab cannot be found
Please enter file name: ch9sample.txt
Words and frequency in the file ch9sample.txt sorted alphabetically
a 20
all 1
almost 1
an 2
and 3
any 1
are 3
as 3
association 1
avoid 1
be 2
because 2
between 1
build 1
builtin 1
but 2
called 2
can 2
computer 1
corresponding 1
creates 1
dict 2
dictionary 7
different 1
each 1
elements 1
english 1
example 2
fact 1
from 1
function 2
general 2
get 1
have 1
if 1
in 5
index 1
indexed 1
indices 3
instead 1
integer 1
integers 1
is 5
it 1
item 1
items 2
key 2
keys 3
keyvalue 2
like 1
list 2
look 1
mapping 1
maps 2
might 1
more 1
name 2
never 1
new 1
no 1
not 2
of 8
on 1
or 1
order 2
pair 1
pairs 1
positions 1
problem 1
result 1
same 2
set 2
should 1
so 1
sometimes 1
spanish 1
strings 1
that 1
that's 1
the 15
think 1
to 4
type 2
unpredictable 1
up 1
use 1
using 1
value 2
values 3
variable 1
we'll 1
which 1
with 2
words 1
you 5
your 1
There are 96 different words in the file.
Do you want to try another file? (y or n)Y
Please enter file name: ch9sample3.txt
Words and frequency in the file ch9sample3.txt sorted alphabetically
a 16
all 1
almost 2
an 2
and 3
any 1
are 2
as 3
association 1
avoid 1
be 2
because 1
between 1
build 1
builtin 1
but 1
called 2
can 2
creates 1
dict 2
dictionary 5
don't 1
each 1
english 1
example 1
from 1
function 2
general 1
have 1
in 2
index 1
indices 2
integers 2
is 3
it 1
item 1
items 2
key 2
keys 2
keyvalue 1
like 1
list 2
mapping 1
maps 2
more 1
name 3
new 1
no 1
of 5
or 1
pair 1
positions 1
set 2
should 1
so 1
sometimes 1
spanish 1
strings 1
that 1
the 7
think 1
to 3
type 2
using 1
value 2
values 2
variable 1
we'll 1
which 1
with 1
words 1
you 2
There are 72 different words in the file.
Do you want to try another file? (y or n)N
Thank you for playing.
>>>
>>>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!