Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python: Here is the original question / assignment: Read Chapter 7 of the textbook. Complete number 8 Name Search from your programming exercises. 8.

In Python:

Here is the original question / assignment:

Read Chapter 7 of the textbook.

Complete number 8 Name Search from your programming exercises.

8. Name Search

If you have downloaded the source code 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. The user should be able to enter a boys name, a girls name, or both, and the application will display messages indicating whether the names were among the most popular. (You can access the Computer Science Portal at www.pearsonhighered.com/gaddis.)

Document each step by pasting an image copy of each step into the discussion board

Discuss any problems or challenges you encountered while completing the exercises.

Common file opening mistakes.

Ensure that you check the box to view file extensions in file explorer. If this is not checked you will most likely name your file myfile.txt.txt. So in file explorer go to view and check the mark that says view file extensions. https://www.howtogeek.com/205086/beginner-how-to-make-windows-show-file-extensionsLinks to an external site.

Make sure that you do not name any files with spaces. Your a developer now.

Make sure your py file runs from the same directory that your text file is in.

When you create a py file complete an initial save as. Put it in the directory your text file is in.

Here is what ive gotten so far:

girls=open("girlnames.txt","r")

boys=open("boynames.txt","r")

g=girls.readlines()

b=boys.readlines()

girls_list=[]

boys_list=[]

for name in g:

girls_list.append((name.strip()).lower())

for name in b:

boys_list.append((name.strip()).lower())

option=(input("Enter 'boy','girl', or 'both': ").lower()).strip()

if option=="boy":

searchname=input("Please enter a boy's name: ")

if searchname in boys_list:

print("{} was a popular boy's name in the USA between 2000 and 2009.".format(searchname))

else:

print("{} was not a popular boy's name in the USA between 2000 and 2009.".format(searchname))

elif option=="girl":

searchname=input("Please enter a girl's name: ")

if searchname in girls_list:

print("{} was a popular girl's name in the USA between 2000 and 2009.".format(searchname))

else:

print("{} was not a popular girl's name in the USA between 2000 and 2009.".format(searchname))

elif option=="both":

boysearchname=input("Enter a boy name: ")

girlsearchname=input("Enter a girl name: ")

if boysearchname in boys_list:

print("{} was a popular boy's name in the USA between 2000 and 2009.".format(boysearchname))

else:

print("{} was not a popular boy's name in the USA between 2000 and 2009.".format(boysearchname))

if girlsearchname in girls_list:

print("{} was a popular girl's name in the USA between 2000 and 2009.".format(girlsearchname))

else:

print("{} was not a popular girl's name in the USA between 2000 and 2009.".format(girlsearchname))

else:

print("Invalid input")

image text in transcribedand my output:

image text in transcribed

My concern is that my program isnt pulling the two text files no matter what I do. I have tried moving them, i've tried downloading and running my classmates successful code, none of it seems to be working. I am using Visual Studio Code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions