Final answer:
This Python program reads names from two files, 'GirlNames.txt' and 'BoyNames.txt', into separate lists, then checks if a user-entered name is among the most popular by seeing if it is present in these lists.
Step-by-step explanation:
Python Program to Check Popularity of Names
To check whether a given boy's name or girl's name is among the most popular names from 2000 to 2009, you can write a Python program that reads the contents of two separate files (GirlNames.txt and BoyNames.txt). Each file contains a list of 200 popular names for the corresponding gender. Once the names are read into separate lists, the user can input names to check their popularity. The program will confirm if each provided name is in the respective list, and thus, if it was one of the most popular names during that time period.
Sample Python Code
The following is an example of how such a program could look:
def read_names_from_file(filename):
with open(filename, 'r') as file:
names = file.read().splitlines()
return names
def check_name_popularity(names_list, name):
return name in names_list
girl_names = read_names_from_file('GirlNames.txt')
boy_names = read_names_from_file('BoyNames.txt')
name_to_check = input('Enter a name to check its popularity: ')
if check_name_popularity(girl_names, name_to_check):
print(f'{name_to_check} is one of the most popular girl's names.')
elif check_name_popularity(boy_names, name_to_check):
print(f'{name_to_check} is one of the most popular boy's names.')
else:
print(f'{name_to_check} is not one of the most popular names.')
Remember to have the text files 'GirlNames.txt' and 'BoyNames.txt' in the same directory as your Python script, or provide the correct path to them.