Question: Python Homework 6 Write a program that analyzes Charles Dickens's David Copperfield. Your program should scan the file copperfield.txt and provide per-chapter statistics for the

Python  Python Homework 6 Write a program that analyzes Charles Dickens's David

Homework 6 Write a program that analyzes Charles Dickens's David Copperfield. Your program should scan the file copperfield.txt and provide per-chapter statistics for the total number of commas, total number of words and average word length Extra Credit Report the title of each chapter Hint Files are read line-by-line which means you'll need to manipulate the input a little bit to get it in a similar format to that of a paragraph from the previous homework. Once you've identified the start of a chapter, you can continue reading lines and appending them to a variable to recreate the chapter text in a single variable. You can then use this variable as if it were the variable containing the paragraph text. All chapters are identified in the format: CHAPTER XX. . Because we are reading one line at a time, a conditional like the one below will return true when it finds a match for the text. You can use this to build logic that says every line read between finding chapter lines is technically the chapter text. f CHAPTERin line print (line) Output Statistics for chapter 1 X AM BORN Total commsa: 456 Total vorda1 4653 Average word length -4156458199011395 Statistica for chapter 2OBSERVE Total comma81 574 Total words: 6246 Average word length: 4.238072366314441 atatistics for chapter 3 (I HAVE A CHANGE Total ccemas: 615 Total worda: 6480 average word length: 4.283024691358024 Statistiea for chapter Total commas: 786 Total vordsa 7987 PALL INTO DIBGRACE Average word length: 4.268185801928134 Statisties for chapter 62 (A LIGHT SHINES ON HY WAY) Total ccmman: 321 Total vordai 3424 Average word length: 4-126168224299065 Statistics for chapter 63 (A VISITOR) Total vordsi 3210 Average word length: 4.210903426791277

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 Databases Questions!