Word Counter Assignment

From Knowledge Kitchen
Jump to navigation Jump to search


Overview

Create a program that analyzes a text file and counts how many time various words are used within it.

User flow

  1. The program asks a user what file to open.
  2. The program then asks the user to enter a comma-separated list of words to analyze within the file.
  3. The program then outputs the frequency of each word within the file.

Sample session

User responses are bold.

What file would you like to open? universal_declaration_of_human_rights_in_nigerian_pidgin_english.txt
What words would you like to search for? wey, dem, unifasiti, ting

... analyzing ... hold on ...

Frequency of word usage within universal_declaration_of_human_rights_in_nigerian_pidgin_english.txt:
    wey              /  19 occurrences
    dem              /  17 occurrences
    unifasiti        /  22 occurrences
    ting             /  63 occurrences

Requirements

  • Include a sample text file along with your code when submitting your assignment. Package both files into a zip file.
  • If the user includes spaces in their list of words (as I have done in the example session above), they should be stripped out and ignored.
  • Capitalization should be ignored.
  • There is no limit to how many words the user can enter.
  • Complete the assignment without using Python's built-in String count() method.

Notes

There are many useful string methods:

In particular, you may find the following methods useful in completing this assignment:


What links here