Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python, please include comments and output babynames.py ## # This program displays the most common baby names. Half of boys and girls in #

image text in transcribedIn Python, please include comments and output

babynames.py

##

# This program displays the most common baby names. Half of boys and girls in

# the United States were given these names in 2011.

#

# The percentage limit to be extracted.

LIMIT = 50.0

def main() :

inputFile = open("babynames.txt", "r")

boyTotal = 0.0

girlTotal = 0.0

while boyTotal or girlTotal

# Extract the data from the next line and split it.

line = inputFile.readline()

dataFields = line.split()

# Extract the individual field values.

rank = int(dataFields[0])

boyName = dataFields[1]

boyPercent = float(dataFields[2].rstrip("%"))

girlName = dataFields[3]

girlPercent = float(dataFields[4].rstrip("%"))

# Process the data.

print("%3d " % rank, end="")

boyTotal = processName(boyName, boyPercent, boyTotal)

girlTotal = processName(girlName, girlPercent, girlTotal)

print()

inputFile.close()

## Prints the name if total

# @param name the boy or girl name

# @param percent the percentage for this name

# @param total the total percentage processed

# @return the adjusted total

#

def processName(name, percent, total) :

if total

print("%-15s" % name, end="")

else :

print("%-15s" % "", end="")

total = total + percent

return total

# Start the program.

main()

babynames.txt

1 Jacob 1.0013% Sophia 1.1297% 2 Mason 0.9637% Isabella 1.0282% 3 William 0.8522% Emma 0.9724% 4 Jayden 0.8378% Olivia 0.8940% 5 Noah 0.8307% Ava 0.8010% 6 Michael 0.8247% Emily 0.7375% 7 Ethan 0.8231% Abigail 0.6847% 8 Alexander 0.7746% Madison 0.6404% 9 Aiden 0.7646% Mia 0.5963% 10 Daniel 0.7521% Chloe 0.5685% 11 Anthony 0.7046% Elizabeth 0.5193% 12 Matthew 0.6981% Ella 0.4947% 13 Elijah 0.6865% Addison 0.4815% 14 Joshua 0.6758% Natalie 0.4475% 15 Liam 0.6632% Lily 0.4224% 16 Andrew 0.6535% Grace 0.3937% 17 James 0.6525% Samantha 0.3817% 18 David 0.6508% Avery 0.3803% 19 Benjamin 0.6430% Sofia 0.3793% 20 Logan 0.6416% Aubrey 0.3715% 21 Christopher 0.6402% Brooklyn 0.3705% 22 Joseph 0.6359% Lillian 0.3571% 23 Jackson 0.6100% Victoria 0.3558% 24 Gabriel 0.6075% Evelyn 0.3473% 25 Ryan 0.5676% Hannah 0.3383% 26 Samuel 0.5564% Alexis 0.3375% 27 John 0.5433% Charlotte 0.3314% 28 Nathan 0.5178% Zoey 0.3309% 29 Lucas 0.5130% Leah 0.3300% 30 Christian 0.5082% Amelia 0.3284%

Write a program that reads a file in the same format as ch07/worked_example_1/babynames.txt and prints all names that are both boy and girl names (such as Alexis or Morgan)

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

Step: 3

blur-text-image

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

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

Is the basis of competition quality, price, or brand?

Answered: 1 week ago

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago

Question

Explain the testing process of accounting 2?

Answered: 1 week ago