Python flow chart and code completion for "uncommented_baby_name.py"

This assignment includes the attached “uncommented baby_names.py” file. Students are to download a copy of this file and in the editor of their choice, add comments to each line of code within the file. There should be 2 types of comments:

1.High-level comments that provide the outline of the main algorithm.

2.In-line comments that explain what each line of code does and highlight any possible issues with this code for programmers that need to maintain this code later.

 

The student should also produce 2 flowchart diagrams based on the code: one flowchart for the main program, and one for the function embedded within the same file. The flowchart should follow all standard conventions including proper shapes, flow lines, and a single entry and exit point.

 

Question 1

Draw 2 flow chart one main program and another function flow chart.

 

2. Question

Includes at least 3 high-level comments stating the major steps and Includes a comment for every line of code written as pseudocode.

the source code is below

 

import os

path = "/Users/user1/data/baby_names/"

myyear = input("Please provide the year to be searched:")

 

while not myyear.isnumeric():

    myyear = ("That's not a number, try again:")

 

while int(myyear) < 1880 or int(myyear) > 2014:

    myyear = input("Number must be between 1880 and 2014, try again:")

 

while not myyear.isnumeric():

    myyear = ("That's not a number, try again:")

    babyname = input("Please provide the baby name to be searched:")

 

while not babyname.isalpha():

    babyname = input("That's not a word, try again:")

    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"  # set the file name

    bnames = []  # declare list name 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)

        for each in f:

            fields = each.split(',')

            bnames.append(fields)

            print("Imported " + file)

            f.close()

    mcount = 0

    fcount = 0

 

    for fields in bnames:

        if baby == fields[0]:

            if 'M' in fields[1]:

                mcount = int(fields[2])

            else:

                fcount = int(fields[2])

    return [mcount, fcount]

 

Need a custom answer at your budget?

This assignment has been answered 6 times in private sessions.

© 2024 Codify Tutor. All rights reserved