Now You Code 2: Character Frequency

Write a program to input some text (a word or a sentence). The program should create a histogram of each character in the text and it's frequency. For example the text apple has a frequency a:1, p:2, l:1, e:1

Some advice:

  • build a dictionary of each character where the character is the key and the value is the number of occurences of that character.
  • omit spaces, in the input text, as they cannot be represented as dictionary keys
  • convert the input text to lower case, so that A and a are counted as the same character.

After you count the characters:

  • sort the dictionary keys alphabetically,
  • print out the character distribution

Example Run:

Enter some text: Michael is a Man from Mississppi.
. : 1
a : 3
c : 1
e : 1
f : 1
h : 1
i : 5
l : 1
m : 4
n : 1
o : 1
p : 2
r : 1
s : 5

Step 1: Problem Analysis

Inputs:

Outputs:

Algorithm (Steps in Program):


In [20]:
## Step 2: Write code here

Step 3: Questions

  1. Explain how you handled the situation where the dictionary key does not exist? (For instance the first time you encounter a character?)

Answer:

  1. What happens when you just press ENTER as opposed to entering some actual text? What can be done about this to provide better feedback.

Answer:

  1. This program is similar to the popular word cloud generators [http://www.wordclouds.com/] you can find on the Web. Describe how this program could be modified to count words instead of characters.

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