Question
This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have
This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment.
You should now have two files one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example
>>>
Enter gender (boy/girl): boy
Enter the name to search for: Michael
Michael was ranked # 7 in 2014 for boy names.
>>> ================================ RESTART ================================
Enter gender (boy/girl): boy
Enter the name to search for: MIchAel
MIchAel was ranked # 7 in 2014 for boy names.
>>> ================================ RESTART ================================
Enter gender (boy/girl): boy
Enter the name to search for: Jeremiah
Jeremiah was ranked # 56 in 2014 for boy names.
>>> ================================ RESTART ================================
Enter gender (boy/girl): girl
Enter the name to search for: olivia
olivia was ranked # 2 in 2014 for girl names.
>>> ================================ RESTART ================================
Enter gender (boy/girl): girl
Enter the name to search for: billie jean
billie jean was not ranked in the top 100 girl names for 2014.
>>> ================================ RESTART ================================
Enter gender (boy/girl): gril
Enter the name to search for: sue
Invalid gender
>>>
Make sure to use try/except blocks to handle the exception if the files are not found or unavailable.
Use the index method on the list to find the baby name. Use a try/except block to handle the exception caused when the name is not found in the file.
Also, check for an invalid gender entry.
Here are the two text files.:
boynames2014.txt
Noah Liam Mason Jacob William Ethan Michael Alexander James Daniel Elijah Benjamin Logan Aiden Jayden Matthew Jackson David Lucas Joseph Anthony Andrew Samuel Gabriel Joshua John Carter Luke Dylan Christopher Isaac Oliver Henry Sebastian Caleb Owen Ryan Nathan Wyatt Hunter Jack Christian Landon Jonathan Levi Jaxon Julian Isaiah Eli Aaron Charles Connor Cameron Thomas Jordan Jeremiah Nicholas Evan Adrian Robert Gavin Brayden Grayson Josiah Colton Austin Angel Jace Dominic Kevin Brandon Tyler Parker Ayden Jason Jose Ian Chase Adam Hudson Nolan Zachary Easton Blake Jaxson Cooper Lincoln Xavier Bentley Kayden Carson Asher Brody Nathaniel Ryder Justin Leo Tristan Juan Luis
girlsnames2014.txt
Emma Olivia Sophia Isabella Ava Mia Emily Abigail Madison Charlotte Harper Sofia Avery Elizabeth Amelia Evelyn Ella Chloe Victoria Grace Aubrey Zoey Natalie Addison Lillian Brooklyn Lily Hannah Layla Scarlett Aria Zoe Samantha Anna Leah Audrey Ariana Savannah Allison Arianna Camila Gabriella Penelope Claire Aaliyah Sadie Riley Skylar Nora Sarah Hailey Kaylee Paisley Kennedy Ellie Peyton Annabelle Caroline Serenity Madelyn Lucy Aubree Alexa Alexis Nevaeh Stella Violet Genesis Mackenzie Bella Autumn Mila Kylie Maya Piper Alyssa Taylor Eleanor Faith Naomi Melanie Katherine Eva Lydia Brianna Julia Ashley Khloe Madeline Ruby Sophie Alexandra London Lauren Gianna Isabelle Vivian Alice Jasmine Hadley
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started