Baby Names

posted by: Ms. Martin 30 May 2011 No Comment

Thanks to Nick Parlante and Stuart Reges for the original project idea!

You will write a program that graphs name popularity for each decade since 1900 based on data given by the Social Security Administration (See their website for the latest data).


  • You will read from two files: names.txt and meanings.txt. You must download them and save them in the same directory as your program.
    • names.txt: each line includes a name followed by 11 decades’ worth of popularity ranking. Notice that a ranking of 1 means the name is the MOST popular. A ranking of 0 means the name was not in the top 1000.
    • meaning.txt: each line starts with a name and continues with the name meaning. You can either present this information visually with the data graph or at the command prompt.
  • A user’s search should be case insensitive. In other words, a search for ‘MeGaN’ should find and graph the record for ‘Megan.’ You could use, for example, the .title() string method.
  • If the user searches for a name not in the files, he or she should get some kind of feedback. This can be ‘sorry, name not found’ at the command prompt or maybe a fail image displayed visually.
  • When graphing the data, notice that a ranking of 1 should be at the top of your graph, a ranking of 500 should be in the middle and a ranking of 0 should be at the very bottom. This is a tricky part to deal with. You will want to use a conditional to deal with the 0 special case.
  • You can choose what your graph looks like. It must include labels and lines for each decade spaced out at least 50 pixels. You can make a line graph or a bar graph. Below are two acceptable examples (you don’t need to graph more than one name or label each point with the name, but those are possible extensions if you finish early).

Getting started

This may seem like a really daunting program but in fact it combines many pieces we have already worked with! You should break down the program into sub-problems that you will solve one at a time.

Looking at sample code is a great way to learn new skills.  Please take a look at the program (download and run it) which uses the file imdb.txt (save in the same folder).  This program displays information from the Internet Movie Database.  Try searching for “america” or “war.”  Notice that all results matching that word will be displayed.

This program shows an example of reading a file by using the open function and the close method.  Notice that you can use a for loop to examine each line of a file.

The IMDB program also demonstrates splitting a line into its different words by using the split string method.  Lists are very similar to strings.  In particular, notice that we can use bracket notation to access a particular element — for example, line[0] lets us access the first element on the line, line[1] the second and so on.

For baby names, here are some isolated tasks you could consider starting with:

  • Write code to read the data file and get a list of popularity values for a specific name entered by the user.
  • Write code to read the meanings file and display the meaning for a specific name entered by the user.
  • Write a function draw_axes that takes a graph size and position and draws the 11 evenly- spaced grid lines you will need for the 11 decades.
  • Write a function graph_list that takes a list as a parameter and uses Turtle Graphics to draw a graph of the list items. You should use a loop based on the list length to do this. Ideally, you would also have parameters for the size of the graph and its position.

Things you will need to know

Write with the turtle: write("<text>")

Make a string called search into all uppercase: search = search.upper()


You have quite a bit of freedom in how you display results — pick interesting colors, a size you like, etc.  Here is one possibility:

For a challenge, try creating a line graph instead:


I understand that not everyone will finish this project in its entirety.  What matters most to me is that you’ve tried out different ideas and documented them in comments.

I expect everyone to get to the point where a user can search for a name and get back popularities and meanings printed at the console.

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.00 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>