Write a program that loads a file called \"sample.txt\" in read mode, reads its
ID: 663760 • Letter: W
Question
Write a program that loads a file called "sample.txt" in read mode, reads its content, and closes the file. Use exception handling to catch any errors.
2. Compute the letter and punctuation distribution in the file. That is, output the number of a’s, the number of b’s, etc. and the number of commas, dashes, and periods. Ignore case when computing this, so ‘A’ and ‘a’ are the same letter. Use lists.
3. Compute the number of words in the file. A word is something that has a single space to either side of it (or only to one side if it starts or ends a sentence), ignoring punctuation. So this sentence: “It was a very nice day, he said.” has 8 words in it.
4. Compute the most frequently occurring word. Use a dictionary.
5. Output all of the data you’ve computed to a file called “statistics.txt”, and format it nicely to be human-legible. Use exception handling to catch any errors.
6. Use functions appropriately. Each major operation should be in a separate function.
Can you please help me come up with a clean and elegant solution to this problem, in Python, using IDLE.
Thanks in advance.
Explanation / Answer
.f.close()
2.
3.
4.
5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.