Question

In: Computer Science

If you have downloaded the source code from this book's companion web site, you will find...

If you have downloaded the source code from this book's companion web site, you will find the following files in the Chapter 07 folder: • GirlNames.txt--This file contains a list of the 200 most popular names given to girls born in the United States from the year 2000 through 2009. • BoyNames.txt--This file contains a list of the 200 most popular names given to boys born in the United States from the year 2000 through 2009. Write a program that reads the contents of the two files into two separate lists, allows a user to input either a girl's name, a boy's name, or both, then tells the user whether the name(s) was/were popular between 2000 and 2009. First, the program should prompt the user to choose a girl's name, a boy's name, or both by entering either 'girl', 'boy', or 'both.' Once they have chosen, they should be able to input a name. If the name was a popular name, like Jacob or Sophia, the program should print "Jacob was a popular boy's name between 2000 and 2009." or "Sophia was a popular girl's name between 2000 and 2009." If the name was not a popular name, like Voldemort, the program should print "Voldemort was not a popular boy's name between 2000 and 2009." If the user chooses to input both a girl and boy's name, ask for the boy's name, then the girl's name, and print two statements in the form mentioned above on two separate lines, with the statement about the boy's name coming first. For example, if the user inputs Voldemort and then Sophia, print: Voldemort was not a popular boy's name between 2000 and 2009. Sophia was a popular girl's name between 2000 and 2009.

My code is working perfectly on boy and girl but it only reads that a name was not popular for boy and girl when running both.

def searchBoyName(boysList, name): #Searching for given boy name in list if name in boysList: #If found print("\n " + str(name) + " was a popular boy's name between 2000 and 2009. \n"); else: #If not found print("\n " + str(name) + " was not a popular boy's name between 2000 and 2009. \n"); def searchGirlName(girlsList, name): #Searching for given girl name in list if name in girlsList: #If found print("\n " + str(name) + " was a popular girl's name between 2000 and 2009. \n"); else: #If not found print("\n " + str(name) + " was not a popular girl's name between 2000 and 2009. \n"); def main(): #Reading data from files boysList = open("BoyNames.txt", "r"); girlsList = open("GirlNames.txt", "r"); #Initializing lists boyNames = []; girlNames = []; #Adding boys names for name in boysList: name = name.strip(); boyNames.append(name); #Adding girls names for name in girlsList: name = name.strip(); girlNames.append(name); #Accepting input from user type = input("\n Enter 'boy', 'girl', or 'both':"); #Searching for boy name if type == "boy": # Reading boy name bname = input("\n\n Input a boy name: "); # Searching searchBoyName(boyNames, bname) #Searching for girl name elif type == "girl": #Reading girl name gname = input("\n\n Input a girl name: "); #Searching searchGirlName(girlNames, gname); #Searching for both elif type == "both": #Searching for given boy name in list bname = input("\n\n Input a boy name: "); #Reading girl name gname = input("\n\n Input a girl name: "); if bname in boysList: #If found print("\n " + str(bname) + " was a popular boy's name between 2000 and 2009. \n"); elif bname not in boysList: #If not found print("\n " + str(bname) + " was not a popular boy's name between 2000 and 2009. \n"); #Searching for given girl name in list if gname in girlsList: #If found print("\n " + str(gname) + " was a popular girl's name between 2000 and 2009. \n"); elif gname not in girlsList: #If not found print("\n " + str(gname) + " was not a popular girl's name between 2000 and 2009. \n"); else: print("\n Invalid selection.... \n"); #Calling main function main();

Solutions

Expert Solution

​​​​​​​


Related Solutions

DO IN JAVA If you have downloaded this book’s source code (the companion Web site is...
DO IN JAVA If you have downloaded this book’s source code (the companion Web site is available at www.pearsonhighered.com/gaddis), you will find the following files in the Chapter 07 folder: GirlNames.txt – This file contains a list of the 200 most popular names given to girls born in the United States for the years 2000 through 2009. BoyNames.txt – This file contains a list of the 200 most popular names given to boys born in the United States for the...
Describe statements of "White Privilege." At the web site you will find Internet sites of individuals...
Describe statements of "White Privilege." At the web site you will find Internet sites of individuals and groups that the author Raymond A. Franklin thinks advocate violence against, separation from, defamation of, deception about, or hostility toward others based upon race, religion, ethnicity, gender or sexual orientation. Select five groups/individuals of those identified at this web site and summarize the purpose of each. http://www.hatedirectory.com/
You are to select 1 business that does not already have a Web site, and develop...
You are to select 1 business that does not already have a Web site, and develop an Internet strategy for it. Most large corporations already have Web sites, so you may have to think of something on a smaller scale such as a local bike store. Sole proprietorship businesses that provide services like car repair, house cleaning, tax preparation, and that use the Internet and similar services are also good options. You will also consider and describe how the business...
You are to develop from the beginning a web site about yourself with regards to your...
You are to develop from the beginning a web site about yourself with regards to your course studies and any certifications you have done so far. This web site provides certain required details about your education/studies which you did. You will design and develop your web site with Notepad/Notepad++, HTML, Java Script and CSS. The purpose of this assignment is for you to build a web site that will contain some details about all of your course degrees you have...
Choose an existing web site that you think can be improved or you have experienced problems...
Choose an existing web site that you think can be improved or you have experienced problems with and explore the site thoroughly. Introduction. List the name and URL of the web site you have chosen, summarize the major purpose(s) of the site, and describe briefly your experience with the web site. Problems and Recommendations Use the Eight Golden Rules: to organize your content (eight subheadings), but please feel free to go beyond these eight rules if you like. For each...
. Find a web site that discusses the Friedman view of the Great Depression, provide the...
. Find a web site that discusses the Friedman view of the Great Depression, provide the link and briefly describe what it says.
1000-1200 WORDS Choose an existing web site that you think can be improved or you have...
1000-1200 WORDS Choose an existing web site that you think can be improved or you have experienced problems with and explore the site thoroughly. Introduction. List the name and URL of the web site you have chosen, summarize the major purpose(s) of the site, and describe briefly your experience with the web site. Problems and Recommendations Use the Eight Golden Rules: to organize your content (eight subheadings), but please feel free to go beyond these eight rules if you like....
On the internet (e.g., the Micron Technologies web site) find the access time and size of...
On the internet (e.g., the Micron Technologies web site) find the access time and size of a state-of-the-art a) DRAM chip b) SRAM chip c) FLASH chip
Go to the IRS Web site (www.irs.gov) and find the 2016 edition of the IRS Publication...
Go to the IRS Web site (www.irs.gov) and find the 2016 edition of the IRS Publication 538 (PDF file), Accounting Periods and Methods. Find the pages on Inventories. What are the revenue procedures that permit qualifying taxpayers and qualifying small business taxpayers to use the cash method for accounting for inventories? Answer the following questions. 1. What page of the publication does the discussion of inventory start? ___________ 2. The qualifying taxpayer under Revenue Procedure(a. 2001-2 b. 2001-10 c. irb02-02)...
4. Find a web site that discusses the Friedman view of the Great Depression, provide the...
4. Find a web site that discusses the Friedman view of the Great Depression, provide the link and briefly describe what it says.                                                                          15 points
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT