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 word_types.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 word_types.py.
Test files:
- angelou.txt
- atwood.txt
- dickinson.txt Test cases
Note that you have to implement two functions: count_word_type and print_plot
```
counts = count_word_type("angelou.txt")
assert counts =={'capitalized': 3, 'punctuated': 8, 'other': 27}
print_plot(counts)
capitalized 7.89% #######
punctuated 21.05% #########################
other 71.05% ###############################################################################
```
```
counts = count_word_type("atwood.txt")
assert counts =={'capitalized': 3, 'punctuated': 10, 'other': 30}
print_plot(counts)
```
capitalized 6.98% ######
punctuated
other
23.26% ##########################
69.77% ########################################################################
```
counts = count_word_type("dickinson.txt")
assert counts =={'capitalized': 15, 'punctuated': 17, 'other': 52}
print_plot(counts)
```
capitalized
17.86% #################
punctuated
20.24% ######################
other
61.90% #######################################################################
Counting word types In this lab session you will

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!