Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python I Chapter 6 Programming Project This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby

Python I Chapter 6 Programming Project This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby names activity we did in class. You should now have two files one called boynames2016.txt and one called girlnames2016.txt - each containing the top 100 names for each gender from 2016. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2016. For example >>> Enter gender (boy/girl): boy Enter the name to search for: Michael Michael was ranked # 8 in 2016 for boy names. >>> ================================ RESTART ================================ Enter gender (boy/girl): boy Enter the name to search for: MIchAel MIchAel was ranked # 8 in 2016 for boy names. >>> ================================ RESTART ================================ Enter gender (boy/girl): boy Enter the name to search for: Jeremiah Jeremiah was ranked # 58 in 2016 for boy names. >>> ================================ RESTART ================================ Enter gender (boy/girl): girl Enter the name to search for: olivia olivia was ranked # 2 in 2016 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 2016. >>> ================================ 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. You may loop through the file, comparing names to find the name. OR, a simpler way is to use the index method on the list to find the baby name (this is covered in Chapter 7). Use a try/except block to handle the exception caused when the name is not found in the file. Make sure to include appropriate comments in your program.

this is what i have already

def main(): try: infile=open("babynames2016.txt","r") girlFile=open("girlnames2016.txt","w") boyFile=open("boynames2016.txt","w") line=infile.readline() while line!="": babynames=line.split() boyFile.write(babynames[1]+" ") girlFile.write(babynames[2]+ " ") line=infile.readline() infile.close() boyFile.close() girlFile.close() except: print('babynames2016.txt file not found.')

return main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

2. What are your challenges in the creative process?

Answered: 1 week ago