Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ADVANCE PYTHON: 1. The code below please and add comments throughout the program to explain what each line of code does. Be sure to include
ADVANCE PYTHON: 1. The code below please and add comments throughout the program to explain what each line of code does. Be sure to include both high level comments for the overall algorithm as well as pseudocode comments for each individual step. Finally, use a diagramming tool (Visio, Lucidchart, MSPaint, paper & pen) to create a flowchart of the code.
the code is below:
import os path = "/Users/user1/data/baby_names/" myyear = input("Please provide the year to be searched:") babyname = input("Please provide the baby name to be searched:") babyname = babyname.capitalize() baby_counts = count_babies(myyear, babyname) print("There were {0} boys and {1} girls with that name in {2}".format( baby_counts[0], baby_counts[1], myyear)) def count_babies(year, baby): file = "yob" + year + ".txt" bnames = [] if file not in os.listdir(path): print("These are not the files you are looking for, move along") return 0 else: f = open(path + file) f.readline() for each in f: fields = each.split(',') bnames.append(fields) f.close() print("Imported " + file) mcount = 0 fcount = 0 for fields in bnames: if baby in fields[0]: if 'M' in fields[1]: mcount = int(fields[2]) else: fcount = int(fields[2]) return [mcount, fcount]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started