Use the command line to create a new directory called lab17 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.
Character Count
Some states require that legal documents not be written above a certain grade level. The Flesch-Kincaid grade level is a numeric score that indicates the minimum grade level in which an average student would be able to understand a text. Writing a function that computes the grade level of text requires being able to count the number of occurances of certain characters.
Create a Python function called count_character(text, character)
in a file called reading_level.py. The function should have two parameters, text, a string of any length, and character, a string consisting of a single character. The function should return the number of times that the input character appears in the text. For example if the program was run with the text "aardvark" and the character "a" the output would be 3. Be sure to write your own test cases that cover all boundary conditions.
Reading Level
Create a Python function called compute_reading_level(text)
in the reading_level.py file. The function should have one parameter, text, which is a string of any length. The function should return the Flesch-Kincaid grade level of the input text. The Flesch-Kincaid grade level equation requires determining the number of syllables in a sentence, which is very difficult for a program to compute without a dictionary. The following equation is an approximation to the Flesch-Kincaid grade level that does not use syllables:
0. 39 * (W / S) + 11. 8 * ((L / 3) / W) − 15. 59
Where W is the total number of words, S is the total number of sentences, and L is the total number of letters. Assume that all sentences end in a period, that all words are separated by a single space, and that all characters that are not a space or period are letters. For example the following sentence:
I do not like them Sam I am. I do not like green eggs and ham.
has 16 words, 2 sentences and 45 letters. So the function would return − 1. 4075. The sentence:
To be or not to be that is the question. Whether tis nobler in the mind to suffer the slings and arrows of outrageous fortune or to take arms against a sea of troubles and by opposing end them.
has 39 words, 2 sentences, and 153 letters. So the function would return 7. 44. . . Be sure to write your own test cases that cover all boundary conditions.
Submission
Please show your source code and run your programs for the instructor or lab assistant. Only programs that have perfect style and flawless functionality will be accepted as complete.