153,187 views
41 votes
41 votes
NAME SEARCH In the Chap07 folder of the Student Sample Programs, you will find the following files: GirlNames.txt—This file contains a list of the 200 most popular names given to girls born in the United States from 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 2000 through 2009. Create an application that reads the contents of the two files into two separate arrays or Lists. The user should be able to enter a boy’s name, a girl’s name, or both, and the application should display messages indicating whether the names were among the most popular.

User Pasosta
by
3.2k points

1 Answer

8 votes
8 votes

Answer:

Step-by-step explanation:

I do not have the files listed in the question so I have made two test files with the same names. This code is written in Python, we are assuming that the names on each file are separated by newlines.

f1 = open("GirlNames.txt", 'r')

f1_names = f1.read()

f1_names_list = f1_names.split('\\')

f2 = open("BoyNames.txt", 'r')

f2_names = f2.read()

f2_names_list = f2_names.split('\\')

print(f1_names_list)

print(f2_names_list)

boy_or_girl = input("Would you like to enter a boy or girl name or both: ").lower()

if boy_or_girl == 'boy':

name = input("Enter name: ")

if name in f2_names_list:

print("Yes " + name + " is in the list of most popular boy names.")

else:

print("No, it is not in the list")

elif boy_or_girl == 'girl':

name = input("Enter name: ")

if name in f1_names_list:

print("Yes " + name + " is in the list of most popular girl names.")

else:

print("No, it is not in the list")

elif boy_or_girl == 'both':

girlname = input("Enter Girl name: ")

if girlname in f1_names_list:

print("Yes " + girlname + " is in the list of most popular girl names.")

else:

print("No, it is not in the list")

boyname = input("Enter name: ")

if boyname in f2_names_list:

print("Yes " + boyname + " is in the list of most popular girl names.")

else:

print("No, it is not in the list")

else:

print("Wrong input.")

NAME SEARCH In the Chap07 folder of the Student Sample Programs, you will find the-example-1
User Teobis
by
2.5k points