Python Program Names: Input files: Assign8 _First_Last.py April 4, 2017 30 GirlN
ID: 3810770 • Letter: P
Question
Python Program Names:
Input files:
Assign8 _First_Last.py
April 4, 2017
30
GirlNames.txt and BoyNames.txt
These are on your flash drive. I also included them on Blackboard.
You will read the two files and load them into two separate lists. The user will ask you to search a name from the girls’ list, the boys’ list, or both.
Description:
1. Start the programs with at least five comments. The top three should be:
# CIS115.600 Assignment 8
# First Last (Where First is your first name and Last is your last name) #Current Date
For the program:
Do Programming Exercise #8 - Name search on pp. 335-336 in your book.
Read both files and put them into two separate list. Program 7-15 might be a good example to
follow. Be sure to strip the .
Ask the user if they want to enter a boy’s name, a girl’s name, or both.
Then ask the user to enter a name.
Search the appropriate list(s) and print out an appropriate message. For the search, you might
consider Program 7-2 as an example.
Note: one name that is both on the girls’ and boys’ lists is “Peyton”.
Handle all possibilities. This is harder than you think.
I will leave the output design to you.
Make sure your variable names are descriptive.
I will allow you to design the output.
Explanation / Answer
GirlNames.txt :
priyanka
swathi
liot
axel
dert
BoyNames.txt :
sumanth
rohit
maxwell
sachin
Virat
Assign8 _First_Last.py :
# CIS115.600 Assignment 8
# Enter your First Last Names
#Date : April 4, 2017
Peyton = raw_input("Enter girl or Boy Name to seach : ");
print Peyton
#reading BoyNmaes file into list
fo = open("BoyNames.txt", 'r')
Boys_list = [x.strip() for x in fo.readlines()]
fo.close();
print "Boys list = " , Boys_list
#reading GirlNmaes file into list
fo2 = open("GirlNames.txt",'r')
Girls_list=[y.strip() for y in fo2.readlines()]
fo2.close();
print "Girls list = " ,Girls_list
#searching for the name in files
for i in Boys_list:
if i == Peyton :
print "The ", Peyton , " is availble in BoyNames.txt file"
else :
for Peyton in Girls_list :
if i == Peyton :
print "The ", Peyton ," is availble in GirlNames.txt file"
else :
print "The searching name is not avaible in both files"
OUTPUT :
akolli@smarupureddy:~$ python Assign8_First_Last.py
Enter girl or Boy Name to seach : sachin
sachin
Boys list = ['sumanth', 'rohit', 'maxwell', 'sachin', 'Virat']
Girls list = ['priyanka', 'swathi', 'liot', 'axel', 'dert', ]
The sachin is availble in BoyNames.txt file
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.