Programming Exercise 15

  < Previous  Next >

Due Date

See the calendar for due date.

Assignment:

Write a program that reads the contents of the two files into two separate lists, allows a user to input either a female name, a male name, or both, then tells the user whether the name(s) was a popular baby name in 2015.
Use the following files for this assignment: femaleBabyNames2015.txt and maleBabyNames2015.txt.
First, the program should prompt the user to choose a female name, a male name, or both by entering either 'female’, 'male’, or 'both.' Once they have chosen, they should be able to input a name. The program should print an appropriate message indicating whether the name printed was a popular male or female baby name in 2015. If the user chooses to check both lists, print statements indicating each result. Your program should include a main() function which opens and reads the files into lists. The main function should call the function searchList(list, name) which will search a given list and return a boolean indicating if the list contained the name argument.

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.
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.
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.
Riley was a popular male baby name in 2015.

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  pe15  pe15.py
To verify your submission, type the following in a terminal window:
handin  pe15

Notes

  1. There's only three names that show up on both files specified above:
    • Avery
    • Hayden
    • Riley
  2. The lists provided above are only the most 200 names for each gender. For the most 1,000 popular names, use the following files: Note, your scripts will be tested in a directory that has the files with only the top 200 names. So make sure the code you submit uses those file names.
  3. Data from: http://www.babynamewizard.com/the-top-1000-baby-names-of-2015-united-states-of-america