CSC 110 Lab Week 10

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 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:

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    23.26% #######################
other         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% #############################################################