Now You Code 1: Word Count

Let's write a program which takes a file name as input, counts the number of words in the file, then outputs the word count.

The program should handle FileNotFoundError as an exception in case you enter a file that does not exist.

Sample Run #1:

Word Count!
Enter Filename: NYC1-romeo.txt
There are 33 words in NYC1-romeo.txt

Sample Run #2:

Word Count!
Enter Filename: testing
File Not Found: testing

Try these files:

  • NYC1-cant-stop-the-feeling.txt
  • NYC1-preamble.txt
  • NYC1-romeo.txt or
  • NYC1-zork.txt

HINT: Read in the file a line at a time, then split the line into words and count each word... and remember your algorithm does not need to account for exceptions... those are programming concerns!

Step 1: Problem Analysis

Inputs:

Outputs:

Algorithm (Steps in Program):


In [10]:
## Step 2: write code here

Step 3: Questions

  1. Where are these files located? Make your own file, add words to it then run with the word count program.

Answer:

  1. Explain a strategy for making this program smarter so that it does not include puncutuation in the word counts?

Answer:

  1. Is it possible to have a file with a word count of 0? Explain.

Answer:

Step 4: Reflection

Reflect upon your experience completing this assignment. This should be a personal narrative, in your own voice, and cite specifics relevant to the activity as to help the grader understand how you arrived at the code you submitted. Things to consider touching upon: Elaborate on the process itself. Did your original problem analysis work as designed? How many iterations did you go through before you arrived at the solution? Where did you struggle along the way and how did you overcome it? What did you learn from completing the assignment? What do you need to work on to get better? What was most valuable and least valuable about this exercise? Do you have any suggestions for improvements?

To make a good reflection, you should journal your thoughts, questions and comments while you complete the exercise.

Keep your response to between 100 and 250 words.

--== Write Your Reflection Below Here ==--