Question: Counting word types In this lab session you will write two functions to read a text file, and count how many words there are in
Counting word types
In this lab session you will write two functions to read a text file, and count how many words there are in the file for each of three types: "capitalized", "punctuated", "other".
Do not count one word twice for example, if the word is capitalized, count it as capitalized only, even when its punctuated. You will only count words that are not capitalized and punctuated under the "punctuated" category. If the word is not "capitalized" nor "punctuated", it should be counted as "other". Do not count empty strings generated by white lines in a text file
Your file name should be wordtypes.py
In this lab session you will write two functions to read a text file, and count how many words there are in the file for each of three types: "punctuated", "other".
Do not count one word twice for example, if the word is capitalized, count it as capitalized only, even when it's punctuated. You will only count words that are not capitalized and punctuated under the "punctuated" category. If the word is not "capitalized" nor "punctuated", it should be counted as "other" Do not count empty strings generated by white lines in a text file
Your file name should be wordtypes.py
Test files:
angelou.txt
atwood.txt
dickinson.txt Test cases
Note that you have to implement two functions: countwordtype and printplot
counts countwordtypeangeloutxt
assert counts capitalized: 'punctuated': 'other':
printplotcounts
capitalized #######
punctuated #########################
other ###############################################################################
counts countwordtypeatwoodtxt
assert counts capitalized: 'punctuated': 'other':
printplotcounts
capitalized ######
punctuated
other
##########################
########################################################################
counts countwordtypedickinsontxt
assert counts capitalized: 'punctuated': 'other':
printplotcounts
capitalized
#################
punctuated
######################
other
#######################################################################
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
