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:
read_text- 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.
clean_text- 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, semi-colon, 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.
get_word_frequencies- 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.
count_syllables- 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 count_syllables(word): ''' Estimates and returns the number of syllables in
the specified word.
Parameters:
word - the word to analyze
Return: number of syllables in word '''
syllables =0
vowels = 'aeiouy'
word = word.lower().strip(".:;?!")
if word[0] in vowels:
syllables +=1
for index in range(1, len(word)):
if word[index] in vowels and word[index-1] not in vowels:
syllables +=1
if word.endswith('e'):
syllables -=1
if word.endswith('le'):
syllables +=1
if syllables ==0:
syllables =1
return syllables
Simply copy and paste this function into your program (you're welcome). There are other variations on this algorithm for counting syllables, but we'll use this one.
count_all_syllables- 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 __name__=='__main__':
main()
As before, this if statement keeps your program from being run when it is initially imported into the Web-CAT 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 triple-quoted docstring technique and format shown below.
def count_syllables(word):
''' 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 single-line 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 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 Programming Questions!