Question: Write a Python function named word_count that takes one str parameter: the input filename. The function shall open the input file, read its contents, and

Write a Python function named word_count that takes one str parameter: the input filename. The function shall open the input file, read its contents, and print out the line count, word count, character count, and input filename (to standard output). This same text should be written into a log file named word_count.log. Each call to the word_count function adds a single line to word_count.log. (For extra credit, only open the file once per function call.)

For example, if the input file is seuss.txt, the printed line should be: 5 21 89 seuss.txt.

seuss.txt (the newline character immediately follows the last letter in each line one fish two fish

 red fish blue fish I am Sam, Sam I am. Do you like green eggs and ham? 

Update the module to include a testing main function that calls your function. For the input file, use seuss.txt. The testing main should run when the module itself is run, but not when the module is imported.

There are exceptions (errors) that could possibly occur when running this function. Describe the conditions that could cause errors. There is no need to write handling code in your function for these errors.

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!