Ask Question

Write a program that reads the contents of the two files into two separate lists. The user should be able to enter a boy's name, a girl's name, or both, and the application will display messages indicating whether the names were among the most popular.

+4
Answers (1)
  1. 13 February, 13:52
    0
    Check Explanation.

    Explanation:

    A programming language is used by engineers, technologists, scientists or someone that learnt about programming languages and they use these programming languages to give instructions to a system. There are many types for instance, c++, python, Java and many more.

    So, the solution to the question above is given below;

    #define the lists

    boyNames=[]

    girlNames=[]

    #open the text file BoyNames. txt

    with open ('BoyNames. txt','r') as rd_b_fl:

    boyNames=rd_b_fl. readlines ()

    boyNames=[name. strip (). lower () for name in boyNames]

    #open the text file GirlNames. txt

    with open ('GirlNames. txt','r') as rd_b_fl:

    girlNames=rd_b_fl. readlines ()

    girlNames=[name. strip (). lower () for name in girlNames]

    #print the message to prompt for name

    print ('Enter a name to see if it is a popular girls or boys name.')

    while True:

    #prompt and read the name

    name=input ('/nEnter a name to check, or / "stop/" to stop: '). lower ()

    # if the input is stop, then exit from the program

    if name=='stop':

    break

    # If the girl name exits in the file, then return 1

    g_count=girlNames. count (name)

    # if return value greater than 0, then print message

    if g_count>0:

    print (name. title () + " is a popular girls name and is ranked "

    +str (girlNames. index (name) + 1))

    # if return value greater than 0, then print message

    #"Not popular name"

    else:

    print (name. title () + " is not a popular girls name")

    ## If the boy name exits in the file, then return 1

    b_count=boyNames. count (name)

    if b_count>0:

    print (name. title () + " is a popular boys name and is ranked "

    +str (boyNames. index (name) + 1))

    # if return value greater than 0, then print message

    #"Not popular name"

    else:

    print (name. title () + " is not a popular boys name")
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that reads the contents of the two files into two separate lists. The user should be able to enter a boy's name, a girl's ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers