Lab 7, CSC 101

Note that this lab is due on February, 27th.

This lab practices text manipulation, the use of lists, and reading from a file.

Download lab7.zip, place it in your cpe101 directory, and unzip the file.

Orientation

Against all bureaucratic stereotypes, the Social Security Administration provides a neat web site showing the distribution of names chosen for kids over the last 100 years in the US ( SSA site).

Every 10 years, the data gives the 1000 most popular boy and girl names for kids born in the US. The data can be boiled down to a single text file as shown below. On each line we have the name, followed by the rank of that name in 1900, 1910, 1920, ... 2000 (11 numbers). A rank of 1 was the most popular name that year, while a rank of 997 was not very popular. A 0 means the name did not appear in the top 1000 that year at all. The elements on each line are separated from each other by a single space. The lines are in alphabetical order, although we will not depend on that.
Example data
...
Sam 58 69 99 131 168 236 278 380 467 408 466
Samantha 0 0 0 0 0 0 272 107 26 5 7
Samara 0 0 0 0 0 0 0 0 0 0 886
Samir 0 0 0 0 0 0 0 0 920 0 798
Sammie 537 545 351 325 333 396 565 772 930 0 0
Sammy 0 887 544 299 202 262 321 395 575 639 755
Samson 0 0 0 0 0 0 0 0 0 0 915
Samuel 31 41 46 60 61 71 83 61 52 35 28
Sandi 0 0 0 0 704 864 621 695 0 0 0
Sandra 0 942 606 50 6 12 11 39 94 168 257
...

We see that "Sam" was #58 in 1900 and is slowly moving down. "Samantha" popped on the scene in 1960 and is moving up strong to #7. "Samir" barely appears in 1980, but by 2000 is up to #798.

You can find a text file with some of the recent names data here

Read the Sample Code

Unzip and read the sample program code, it uses pygame to visualize how popular a name is over time. For example, here is a graph of the popularity of the name `Zoe' over time:

and the graph for `Aaron':

Note that this code, will prompt the user to enter a new baby name to plot in the console window. Feel free to type your name and plot it's popualarity over the last 100 years.

Strings

String practice, now you need to modify the program to handle the fact that we are all prone to mis-spellings and that many names have various spellings. You will need to modify the code so that it will return information for four names "close" to the name being searched for. You must implement a search for alternative names with the following alternative `spellings':

  1. 'e' and 'a' are interchangable
  2. 'y' can be replaced by 'ie'
You must then search for these alternative spellings and if you did not find 3 alternative spellings, then you must search for any name with a matching substring of the name being sought (specifically the first 3 letters). Note that you should output to the console all the alternative names you are searching for (including the original name). For example:
Enter a name to search for: Katy
You entered Katy
alternative names: Katy
alternative names: Kety
alternative names: Katie
alternative names: Katarina
alternative names: Kate

You then need to change the program so that it will draw the results for the popularity for the four alternative names as well (only plotting those names that are actually found in the name data). For example (note that 'Kety' was an alternative spelling, but was not found in the name list so is not plotted):

Work incrementally, first write a function to search for and identify the near-by names and then add the code to draw the nearby names, with different colors to labels for each graph. Another example output might look like:
Enter a name to search for: Charles
You entered Charles
alternative names: Charles
alternative names: Cherles
alternative names: Charlas
alternative names: Chad
alternative names: Chadd
alternative names: Chadrick

Demonstration

Demonstrate your program's results to your instructor for a handful of names. Here are a few more examples (note that for short names like 'Amy' you may end up with repeated results - you do not need to check for these redundancies for this lab).
Enter a name to search for: Amy
You entered Amy
alternative names: Amy
alternative names: Emy
alternative names: Amie
alternative names: Amy
alternative names: Amya

Enter a name to search for: Elena
You entered Elena
alternative names: Elena
alternative names: Alena
alternative names: Elana
alternative names: Elene
alternative names: Eleanor
alternative names: Eleanora