Question: 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
Get step-by-step solutions from verified subject matter experts
