Question: Code Requirements: All code you write for this project should be contained in this file. Your program should include the following functions: read _ text
Code Requirements:
All code you write for this project should be contained in this file.
Your program should include the following functions:
readtext This function should accept a string parameter representing the input file name to process and return a single string containing all text from the file. This string will be referred to as the raw text.Use a with statement and a single call to the read function to read the file contents.
cleantext This function should accept a string representing the raw text see above and return a corresponding string in all lowercase and with the following characters removed: comma, semicolon, colon, period, question mark, exclamation point, left square bracket, right square bracket, asterisk, left paren, right paren, dash, single quote character, and double quote character. Use a for loop to replace each of those characters with the empty character The string returned will be referred to as the cleaned text.
getwordfrequencies This function should accept a list of all words in the cleaned text see above and return a dictionary containing a frequency count of all words. The dictionary keys are the word and the values are the count number of times that word appears for each word. Note that the parameter to this function is a list of individual words, not one string.
countsyllables This function accepts a string representing a single word and returns an estimate of the number of syllables in that word. This function is provided for you in its entirety here:
def countsyllablesword: Estimates and returns the number of syllables in
the specified word.
Parameters:
word the word to analyze
Return: number of syllables in word
syllables
vowels 'aeiouy'
word word.lowerstrip:;
if word in vowels:
syllables
for index in range lenword:
if wordindex in vowels and wordindex not in vowels:
syllables
if word.endswithe:
syllables
if word.endswithle:
syllables
if syllables :
syllables
return syllables
Simply copy and paste this function into your program youre welcome There are other variations on this algorithm for counting syllables, but we'll use this one.
countallsyllables This function accepts a list of all words in the cleaned text and returns the sum of all syllables in all words.
main This function represents the main program, which reads the file name to process from the user and, with the assistance of the other functions and some calculations of its own, produces all output. Do not print output in any function other than main.
The number of sentences should be determined by the number of periods, question marks, and exclamation points found in the raw text. Hint: use the string count method.
Note that the number of unique words in the text is the same as the number of keys in the frequencies dictionary.
In the main function, after printing the statistics, use a while loop to check the count of as many words as the user would like. Convert the checked word to all lowercase letters so that case is ignored when looking up the count in the frequencies dictionary.
You may create other functions if desired, but make sure all of the ones specified above are represented.
Other than the definitions of the functions described above, the only code in the module should be the following, at the end of the file:
if namemain:
main
As before, this if statement keeps your program from being run when it is initially imported into the WebCAT test environment. But your program will run as normal in Thonny. Note that there are two underscore characters before and after name and main.
Do NOT use techniques or code libraries in this program that have not been covered in this course.
For each function, include an appropriate comment describing the function, its parameters if any and return value if any Use the triplequoted docstring technique and format shown below.
def countsyllablesword:
Estimates and returns the number of syllables in
the specified word.
Parameters:
word the word to analyze
Return: number of syllables in word
# code here
You can include additional singleline comments in your program code to explain specific processing if needed.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
