Question
Asked Oct 11, 2019
71 views

I am having trouble writing a python program that opens a file that contains baby names. One file for boys and one for girls. The user inputs a name and the program searches the list to see if the name is in either file. I have the loop set and the program runs with no exception error but no matter what name is entered, the program does not find it.

check_circle

Expert Answer

Step 1

To run this code, make all the files Boys.txt, Girls.txt and .py files in same folder.

input() is used to input string.

capitalize() used to capitalize initial letter of string.

open() is used to opening a file.

Boysfiledata variable is used to stored boys file data from a file and girlfiledata variable is used to stored girls file data from a file.

Step 2

Boys.txt contains

Jack

James

Jhon

David

Joseph

Thomes

Logan

 

Girls.txt contains

Sophia

Mia

Linda

Mary

Jessica

Isabella

Emma

help_outline

Image Transcriptionclose

girls.txt boys.txt Sophia pack Mia James Linda Jhon Mary David Jessica Joseph Isabella Thomes Emmal Logan

fullscreen
Step 3

Program code:

#taking input from user

name=input("Enter the name of baby: ").capitalize()

#opening boys.txt files

boysfiledata = open('boys.txt','r')

#opening girls.txt files

girlfiledata = open('girls.txt','r')

#Checking for the name in boys file data

if name in boysfiledata.read():

    #printing statement

    print("name found in boys file")...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: The category of operating system used for handheld devices.

A:  Handheld DevicesA handheld device is an electronic or a computing device that can be carried in our...

question_answer

Q: The print is very small. I apologize in advance for this.  With this homework that has already been ...

A: High Level DesignFrom the limited information that has been provided here, here are the suggestions:...

question_answer

Q: Please explain how you solve the follwing problem:

A: a) Set of nullable variables is {A, B, C} as A and C will be null for productions A -> λ and C-&g...

question_answer

Q: In C++. Data canvas is a file with bunch of random words.        Data canvas: aahs aals abas abba ab...

A: Program Instructions:Use the open() function of fstream to open the file.Use do-while and while loop...

question_answer

Q: In my C++ program I am trying to have a series of if statements check if a user input is negative, n...

A: To check the input is of the given type (double), use the following:if (cin >> numberOfShares)...

question_answer

Q: CHALLENGE 3.16.2: Alphabetic replace. ACTIVITY Replace any alphabetic character with ' in 2-characte...

A: Program://include the required header files#include <iostream>#include <string>#include ...

question_answer

Q: How important is wifi to expansion of computer poliferation

A: Importance of Wi-Fi expansion to computer proliferation:Increased scalability:Wi-Fi is used to avoid...

question_answer

Q: In C++ Create a function that takes in an array and outputs the min, max and average of the array to...

A: A function is to be created in C++ that will take in an array and will results with minimum, maximum...

question_answer

Q: A bit confused on where to begin this program. I'm confused by the information I'm being given I thi...

A: In this program user wants to perform following tasks:    1.Taking inputs as a (A, B, C).     2. Cal...