Question: Instructions/Design We will do some basic data analysis on information stored in external files. Pyton4E_Source_Code.zip GirNames.txt contains a list of the 200 most popular names

Instructions/Design

We will do some basic data analysis on information stored in external files.

Pyton4E_Source_Code.zip

GirNames.txt contains a list of the 200 most popular names given to girls born in US from year 2000 thru 2009

Emily Madison Emma Olivia Hannah Abigail Isabella Samantha Elizabeth Ashley Alexis Sarah Sophia Alyssa Grace Ava Taylor Brianna Lauren Chloe Natalie Kayla Jessica Anna Victoria Mia Hailey Sydney Jasmine Julia Morgan Destiny Rachel Ella Kaitlyn Megan Katherine Savannah Jennifer Alexandra Allison Haley Maria Kaylee Lily Makayla Brooke Mackenzie Nicole Addison Stephanie Lillian Andrea Zoe Faith Kimberly Madeline Alexa Katelyn Gabriella Gabrielle Trinity Amanda Kylie Mary Paige Riley Jenna Leah Sara Rebecca Michelle Sofia Vanessa Jordan Angelina Caroline Avery Audrey Evelyn Maya Claire Autumn Jocelyn Ariana Nevaeh Arianna Jada Bailey Brooklyn Aaliyah Amber Isabel Danielle Mariah Melanie Sierra Erin Molly Amelia Isabelle Madelyn Melissa Jacqueline Marissa Shelby Angela Leslie Katie Jade Catherine Diana Aubrey Mya Amy Briana Sophie Gabriela Breanna Gianna Kennedy Gracie Peyton Adriana Christina Courtney Daniela Kathryn Lydia Valeria Layla Alexandria Natalia Angel Laura Charlotte Margaret Cheyenne Mikayla Miranda Naomi Kelsey Payton Ana Alicia Jillian Daisy Mckenzie Ashlyn Caitlin Sabrina Summer Ruby Rylee Valerie Skylar Lindsey Kelly Genesis Zoey Eva Sadie Alexia Cassidy Kylee Kendall Jordyn Kate Jayla Karen Tiffany Cassandra Juliana Reagan Caitlyn Giselle Serenity Alondra Lucy Kiara Bianca Crystal Erica Angelica Hope Chelsea Alana Liliana Brittany Camila Makenzie Veronica Lilly Abby Jazmin Adrianna Karina Delaney Ellie Jasmin

BoyNames.txt contains a list of the 200 most popular names given to boys born in US from year 2000 thru 2009

Jacob Michael Joshua Matthew Daniel Christopher Andrew Ethan Joseph William Anthony David Alexander Nicholas Ryan Tyler James John Jonathan Noah Brandon Christian Dylan Samuel Benjamin Zachary Nathan Logan Justin Gabriel Jose Austin Kevin Elijah Caleb Robert Thomas Jordan Cameron Jack Hunter Jackson Angel Isaiah Evan Isaac Mason Luke Jason Gavin Jayden Aaron Connor Aiden Aidan Kyle Juan Charles Luis Adam Lucas Brian Eric Adrian Nathaniel Sean Alex Carlos Bryan Ian Owen Jesus Landon Julian Chase Cole Diego Jeremiah Steven Sebastian Xavier Timothy Carter Wyatt Brayden Blake Hayden Devin Cody Richard Seth Dominic Jaden Antonio Miguel Liam Patrick Carson Jesse Tristan Alejandro Henry Victor Trevor Bryce Jake Riley Colin Jared Jeremy Mark Caden Garrett Parker Marcus Vincent Kaleb Kaden Brady Colton Kenneth Joel Oscar Josiah Jorge Cooper Ashton Tanner Eduardo Paul Edward Ivan Preston Maxwell Alan Levi Stephen Grant Nicolas Omar Dakota Alexis George Collin Eli Spencer Gage Max Cristian Ricardo Derek Micah Brody Francisco Nolan Ayden Dalton Shane Peter Damian Jeffrey Brendan Travis Fernando Peyton Conner Andres Javier Giovanni Shawn Braden Jonah Cesar Bradley Emmanuel Manuel Edgar Erik Mario Edwin Johnathan Devon Erick Wesley Oliver Trenton Hector Malachi Jalen Raymond Gregory Abraham Elias Leonardo Sergio Donovan Colby Marco Bryson Martin

Hint: See Program 7-15 read_list.py for example of reading a file's contents into a list and using a loop to strip each Here is the high-level algorithm open BoyNames.text for reading read all lines into a list close the file while there are elements in list strip the from each element open GirlNames.txt for reading read all lines into a list close file while there are elements in list strip from each element get user input for boy get user input for girl display result for boy's name entered by user (you need a decision structure as output depends on user input) display result for girl's name entered by user (you need a decision structure as output depends on user input)

Input: a boy's name, a girl's name, or 'N' for none Output: messages indicating whether the names were among the most popular

Note: Use a try/except to catch IOError as anytime we deal with external files, problems may occur (file doesn't exist, we don't have permissions, disk is corrupted, and so on).

Sample Input/Output

IMPORTANT NOTE: The external files MUST be in same directory as your source code.

You may run your code on the command line/system prompt (as I have done) OR from IDLE (Run->Run Module or F5).

Here is first run showing output when user input for both boy and girl are popular names (user input shown in italics/bold ).

 Enter a boy's name, or N if you do not wish to enter a boy's name: Michael Enter a girl's name, or N if you do not wish to enter a girl's name: Emma Michael is one of the most popular boy's names. Emma is one of the most popular girl's names. 

Here is a second run where user says 'N' to entering names

$ python babyname.py Enter a boy's name, or N if you do not wish to enter a boy's name: N Enter a girl's name, or N if you do not wish to enter a girl's name: N You chose not to enter a boy's name. You chose not to enter a girl's name. 

Here is third run showing user input with a girl name not in the GirlNames.txt file:

$ python babyname.py Enter a boy's name, or N if you do not wish to enter a boy's name: John Enter a girl's name, or N if you do not wish to enter a girl's name: Ada John is one of the most popular boy's names. Ada is not one of the most popular girl's names.

Note: We will test code with THREE sample runs:

  • First run uses the names Michael and Emma (see sample run above)
  • Second run user enters N for both of the prompts (answer N for boys and N for girls)
  • Third run we enter names of our choice but at least one is NOT popular

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!