QuestionQuestion

1. In a Python program smaller_n.py, write a function smaller_than_n_list(input_list, n) that accepts two arguments: an input_list, and a number n. Assume that the list contains numbers. The function should return a list of all of the numbers in the input_list that are less than the number n.

The program should have a main() function that initializes (hardcodes, no user input required) the list of numbers that you come up with (10 or so should do) and the number n. You should display the original list and the number n. Then display the list of numbers smaller than n by calling smaller_than_n_list() and display the returned results.
E.g.
Number: 6
List of numbers:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
List of numbers that are smaller than 6:
[1, 2, 3, 4, 5]

2. 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 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 Python program name_search.py that reads the contents of the two files into two separate lists. You will need to strip the elements of each list of the newline. 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.

You can ask the user "Enter a boy's name, or N if you do not wish to enter a boy's name: " and "Enter a girl's name, or N if you do not wish to enter a girl's name: "

To display the results you will want one of the following: "You chose not to enter a boy's name." or
“ is one of the most popular boy's names." or “ is not one of the most popular boy's names."
AND one of the following:
"You chose not to enter a girl's name." or
“ is one of the most popular girl's names." or “ is not one of the most popular girl’s names."

It is fine for the program to be case sensitive. Total 10 points.
Extra Credit:
Create a new file name_search_ec.py that loops until the user types ‘exit’.

Create a list of all the names that the user searched for (regardless of whether they were popular or not) before the program terminates and write that list to a separate .txt file called NamesSearched.txt. Make sure each item is on a newline in your file.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

boy_names = []
for line in open('BoyNames.txt'):
    boy_names.append(line.strip())

girl_names = []
for line in open('GirlNames.txt'):
    girl_names.append(line.strip())

# Main method for program execution
def main():
    boy_name = input("Enter a boy's name, or N if you do not wish to enter a boy's name: ")

    if boy_name == "":
       print("You chose not to enter a boy's name.")
    else:
       popular = False
       for name in boy_names:
            if name.lower() == boy_name.lower():
                popular = True
       if popular == True:
            print(boy_name, "is one of the most popular boy's names.")
       else:
            print(boy_name, "is not one of the most popular boy's names.")

    print("")

    girl_name = input("Enter a girl's name, or N if you do not wish to enter a girl's name: ")

    if girl_name == "":
       print("You chose not to enter a girl's name.")
    else:
       popular = False
       for name in girl_names:...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$18.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats