Programming Exercise 15 |
< Previous Next > |
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.
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.
handin pe15 pe15.pyTo verify your submission, type the following in a terminal window:
handin pe15