In languages that use the same or similar alphabets, some characters will occur with greater frequency that others. Consider the Latin alphabet, for example, used by most of Western and Central Europe and other parts of the world. Some languages, for example, may not use all of the 26 characters that we are used to. You can learn a lot about languages by comparing the relative frequencies of character use.

A table of frequencies might look something like this:
          *     *               
          *     *               
          *   * * *             
          *   * * *             
          *   * * *             
        * *   * * *             
      * * *   * * *             
      * * * * * * * *           
      * * * * * * * *           
      * * * * * * * * *         
      * * * * * * * * *         
      c d e l m n o p v 
  

In this project, we will write a program that takes a str object containing text (which may be quite long!) and counts the occurrence of each English letter A-Z. We will create a kind of bar graph called a histogram and display it in two forms - one horizontal and one vertical. This project will require you to write several loops that process the integer variables in a list - as well as understanding how to take advantage of data types (esp. the relationship between integers and characters as distinct -- but related -- data types), how to use a constructor object, and how to use a method (even if you do not understand it's inner workings).

(Please note: Be mindful of the use of the term "list". On one hand, in everyday life, it's a generic term for a sequence of things. In Python, however, list is a specific type of object that keeps track of a squence of other data objects!)

You can find initial versions of the histogram.py and histogram_cli.py source files in project_01.zip. As always, download and unzip this file on your removable media (or your own computer).

This program takes advantage something called "lorem ipsum" text, which is essentially partially-scrambled Latin text used as filler in graphic design and publishing. There are a number of websites out there that generate "lorem ipsum" text, sometimes in large amounts. For this program, we will be getting this text from http://loripsum.net, which allows us to request a specific number of paragraphs and specify their length. How this program will work is as follows:

For this project, you will be working in both code files -- histogram_cli.py and histogram.py -- writing the code that enables the program to work. The individual steps are in the comments in the files, but I'll also go over them briefly here:

    In histogram_cli.py...
  1. Declare your variables. (Details in code comments)
  2. Set up one while loop, that will encompass two others, along with the majority of the code in the file. It will allow repeated execution of the rest of the program, until the user indicates to stop.
  3. Prompt the user for how many paragraphs, but only allow a number within the specified range.
  4. Prompt the user for how long paragraphs should be, but only allow a number within the specified range.
  5. Set your counting list to zero, using a loop.
  6. Generate the text. Although the method is given, and you don't necessarily need to understand its inner working, you should know how to call it and what to pass to it.
  7. Count how many of each alphabetic character.
  8. Construct the Histogram object and call it's drawing methods. Study the Histogram class so that you are familiar with it's constructor and other methods, know how they work, and know what they return (or don't return).
    (BE AWARE: At this point, we will not yet have covered Python classes/objects formally in the course, so it will be VERY easy to mess this part up, if you don't know what you're doing! DO NOT proceed with your coding until you KNOW that you are doing this part correctly!)
  9. Ask if the user wants to do it again. Don't forget to close your outer loop and test the condition, specified in the code comments.
  10. In histogram.py...
  11. We may have very large values in the values list supplied as a parameter to the constructor. Since we want to limit the size of the histogram bar graph to max_length, we need to scale the data in the values list when we copy it into the instance copy of the data in the list. This consists of two loops. The first loop finds the largest value in the values list. (Declare, initialize, and use a variable named something like max_value).
  12. The second loop multiplies each value in the values list by the max length we want for bars (max_length) and divides by the largest value found (max_value).
  13. In the draw_hor method, your code must draw a horizontal bar graph of the data in the list of values. (See sample output) This will require two nested loops. The outer loop will be a scan through each element of the values list and the inner loop will print an asterisk from 1 through the value in the outer loop element of the values list. You may also want to print the values list integer at the end of each bar of asterisks, even though this is not in the sample output.
  14. In the draw_ver method, your code must draw a vertical bar graph of the data in the values list. (See sample output) This is a little trickier than the horizontal bar graph. You still need two nested loops. The outer loop will count down through all the values from max_length to 1 to print each line. The inner loop will print a piece of each line for each value (index into the values list). If the count for the value is greater than or equal to the decreasing count of the outer loop, print an asterisk with a space on either side of it. If the count for the value is not greater than or equal to the value of the outer loop count, print an equivalent number of spaces to maintain the column alignment but not show the "bar" in this column.
See also the section on testing your program after the sample output.