Need help with the code for this assignment.
Python Assignment: List and Tuples
We will do some basic data analysis on information stored in external files.
GirNames.txt
contains a list of the 200 most popular names given to girls born
in US from year 2000 thru 2009: (copy link and create a txt file):
https://docs.google.com/document/d/11YCVqVTrzqQgp2xJqyqPruGtlyxs2X3DFWn1YUb3ddw/edit?usp=sharing
BoyNames.txt
contains a list of the 200 most popular names given to boys born in
US from year 2000 thru 2009 (copy link and create txt file):
https://docs.google.com/document/d/12XrZdpMxhs16PZ_fmCcR_5xEE5PDHd1XFNmAfZUWyvU/edit?usp=sharing
Here is the high-level algorithm (you still have work to
do):
open BoyNames.text for reading
read all lines into a list
close the file
while there are elements in list
strip the \n from each element
open GirlNames.txt for reading
read all lines into a list
close file
while there are elements in list
strip \n from each element
get user input for boy
get user input for girl
display result for boy's name entered by user (you
need a decision structure as output depends on user
input)
display result for girl's name entered by user
(you need a decision structure as output depends on user
input)
Input: a boy's name, a girl's name, or 'N' for
none
Output: messages indicating whether the names were
among the most popular
Note: Use a try/except to catch IOError
as anytime we deal with external files, problems may occur (file
doesn't exist, we don't have permissions, disk is corrupted, and so
on).
Note: We will test code with THREE sample runs:
Sample Output:
Here is first run showing output when user input for both boy and girl are popular names (user input shown in italics/bold ).
Enter a boy's name, or N if you do not wish to enter a boy's name: Michael Enter a girl's name, or N if you do not wish to enter a girl's name: Emma Michael is one of the most popular boy's names. Emma is one of the most popular girl's names.
Here is a second run where user says 'N' to entering names
$ python babyname.py Enter a boy's name, or N if you do not wish to enter a boy's name: N Enter a girl's name, or N if you do not wish to enter a girl's name: N You chose not to enter a boy's name. You chose not to enter a girl's name.
Here is third run showing user input with a girl name not in the GirlNames.txt file:
$ python babyname.py Enter a boy's name, or N if you do not wish to enter a boy's name: John Enter a girl's name, or N if you do not wish to enter a girl's name: Ada John is one of the most popular boy's names. Ada is not one of the most popular girl's names.
#try and except for IOerror
try:
fboys =open("boynames.txt",'r');
except:
print("failed to open boynames.txt");
try:
fgirls =open("girlnames.txt",'r');
except:
print("failed to open girlnames.txt");
#lines read to list
boysPopular=fboys.readlines();
length=len(boysPopular); #length of list
i=0;
#strip and use lower case to save names
while i<length:
boysPopular[i]=boysPopular[i].strip().lower();
i+=1;
fboys.close()
#lines read to list
girlsPopular=fgirls.readlines();
length=len(girlsPopular);
i=0;
#strip and use lower case to save names
while i<length:
girlsPopular[i]=girlsPopular[i].strip().lower();
i+=1;
fgirls.close();
#get name and store in lower case for comparison
boyName=input("Enter a boy's name, or N if you do not wish to enter
a boy's name: ").lower();
if boyName != 'n':
if boyName in boysPopular:
#capitalize for better viewing
print(boyName.capitalize(),"is among the most popular boys
name.");
else:
print(boyName.capitalize(),"is not among the most popular boys
name.");
#get name and store in lower case for comparison
girlName=input("Enter a girl's name, or N if you do not wish to
enter a girl's name: ").lower();
if girlName != 'n':
#capitalize for better viewing
if girlName in girlsPopular:
print(girlName.capitalize(),"is among the most popular girls
name.");
else:
print(girlName.capitalize(),"is not among the most popular girls
name.");




Thanks
Need help with the code for this assignment. Python Assignment: List and Tuples We will do...
Visual Basic Question In the Chap9 folder of the student sample programs, 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 2000 to 2012 BoyNames.txt - This file contains a list of the 200 most popular names given to boys born in the United States from 2000 to 2012 Create an application that reads the contents of the two files into...
The text files boynames.txt and girlnames.txt, which are included in the source code for this book, contain lists of the 1,000 most popular boy and girl names in the United States for the year 2005, as compiled by the Social Security Administration. These are blank-delimited files where the most popular name is listed first, the second most popular name is listed second, and so on to the 1,000th most popular name, which is listed last. Each line consists of the...
I need help with this question for programming. The language we use is C++ The program should ask the user if they want to search for a boy or girl name. It should then ask for the name search the appropriate array for the name and display a message saying what ranking that name received, if any. The name files (BoyNames.txt and GirlNames.txt) are in order from most popular to least popular and each file contains two hundred names. The...
Python Assume you have a file Athletes.txt--This file contains a list of the 200 most popular Athlete names. Write a program that reads the contents of the file into a list, allows a user to input name of an Athlete, then tells the user whether the name was popular. First, the program should prompt the user to input an Athlete's name, If the name was a popular name, like “Tiger Wood” or “Roger Federer” , the program should print "Tiger...
The code will not run and I get the following errors in Visual Studio. Please fix the errors. error C2079: 'inputFile' uses undefined class 'std::basic_ifstream<char,std::char_traits<char>>' cpp(32): error C2228: left of '.open' must have class/struct/union (32): note: type is 'int' ): error C2065: 'cout': undeclared identifier error C2065: 'cout': undeclared identifier error C2079: 'girlInputFile' uses undefined class 'std::basic_ifstream<char,std::char_traits<char>>' error C2440: 'initializing': cannot convert from 'const char [68]' to 'int' note: There is no context in which this conversion is possible error...
Python installation: Install Python 3 as described here. (We will work with Windows PC's.) Launch IDLE Enter the program listed in the attached file: "First program in IDLE". Save a "ProgA.py" Debug until code runs correctly. Take a screenshot of the correct output Save as "YourLastName_IDLE1.png" Upload here How do you debug # First Python Program #Fill date here # Name: Fill name here # _________________________ first = input("Enter first name:") last = input("Enter last name:") print("Hello " + first...
PYTHON I need help with this Python problem,
please follow all the rules! Please help! THANK YOU!
Bonus Question Implement an efficient algorithm (Python code) for finding the 11th largest element in a list of size n. Assume that n will be greater than 11. det find 11th largest numberlissy Given, lissy, a list of n integers, the above function will return the 11th largest integer from lissy You can assume that length of lissy will be greater than 11....
Could anyone please help with this Python code assignment? In this programming assignment you are to create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The count of how many numbers are in the file. The average of the numbers. The average is the sum of the numbers divided by how many there are. The maximum value. The...
It's in Python 3. Please make sure it displays correct strings
lenght
And
displays correct character lenght
1 def sum list(numbers): Sums a list of integers param numbers: a list of intege rs return: the sum of the integers in numbe rs def get_string_lengths (st rings) : 10 11 Given a list of strings, return a list of intege rs representing the lengths of the input strings :param strings: a list of strings return: a list of integers represent ing...
Python program
- Write a Python program, in a file called sortList.py, which, given a list of names, sorts the names into alphabetical order. Use a one dimensional array to hold the list of names. To do the sorting use a simple sorting algorithm that repeatedly takes an element from the unsorted list and puts it in alphabetical order within the same list. Initially the entire list is unsorted. As each element is placed in alphabetical order, the elements in...