Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hey I need help with this question don't understand how to do it must use try and except in code for python cheers . Write
Hey I need help with this question don't understand how to do it must use try and except in code for python cheers
. Write a Python program to complete the following steps: prompt the user to enter a filename, read through a list of words from the file, convert all words into lower case, close the input file, count the frequency of each word using a dictionary, print the word-frequency dictionary in sorted keys (alphabetically) order as shown in the examples below, and Use try-except block to handle any exceptions that may occur. Note: If the file cannot be opened, the function should print "ERROR: The file 'xxx' does not exist." where xxx indicates the filename. Note: remember to close the file properly if the file can be opened. You *must* use the try... except syntax and handle the FileNotFoundError in your solution. For example: Input Result temp.txt Enter a filename: temp.txt $200:1 a:2 collect:1 do: 2 go:1 is: 2 not:2 only:1 pass:1 test:2 this: 2 error.txt Enter a filename: error.txt ERROR: The file 'error.txt' does not exist. Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) 1 -try: 2 except FileNotFound: 3Step 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