Programming Exercise 16

  < Previous  Next >

Due Date

See the calendar for due date.

Assignment:

Write a program that reads a file with baby names in it. Store the contents of the file into two separate lists of tuples (one list for each gender). Ask the user which list (or both) that they want to search, then for a name. Report how many babies share that name for the specified list(s).
Use the following input file: babyNamesAndCounts.csv. The input file has the following columns:

  1. Name
  2. Gender (F or M)
  3. Number of babies
Your program should include a main() function which opens and reads the file into lists of tuples. Use the gender column to determine which list of tuples each entry should be included in. The main function should call the function searchList(list, name) which will search a list and return a integer indicating how many babies share that name.

Examples

The following are examples of correct execution (with the text in bold being the input from the user):
Please enter 'female', 'male', or 'both' to search respective list(s): both
Please enter a name to search for: Alexander

Alexander was not a popular female baby name in 2015.
Alexander was a popular male baby name in 2015 with 14,460 babies.
Please enter 'female', 'male', or 'both' to search respective list(s): male
Please enter a name to search for: Christopher

Christopher was a popular male baby name in 2015 with 9,742 babies.
Please enter 'female', 'male', or 'both' to search respective list(s): both
Please enter a name to search for: Riley

Riley was a popular female baby name in 2015 with 5,707 babies.
Riley was a popular male baby name in 2015 with 2,069 babies.

Submission

Submit your python script using the handin program. For handin, for this lab, type the following in a terminal window exactly as it appears:
handin  pe16  pe16.py
To verify your submission, type the following in a terminal window:
handin  pe16

Notes

  1. Data from: http://www.babynamewizard.com/the-top-1000-baby-names-of-2015-united-states-of-america