"""
Name:


"""

##################################################

def main():
    """
    Your program will read in the data set (already done for you below) and
    then prompt the user with the menu. Each time the user makes a selection
    from the menu, you should perform the appropriate action. Once the user
    asks to quit, the program should end.

    Be sure to use the functions you written above to complete the program.
    """
    dataset = read_names()
    print "Welcome to the New York State baby database."

    quit = False
    while not quit:
        choice = menu()
        # You need to add code to perform the rest of the program here.
        # Until you do, it just prints the menu and quits right away.
        if choice == 1:
            year = valid_int("What year are you interested in? ", 2007, 2011)
            babies_born = babies_born_in(dataset, year)
            print "In %d, %d babies were born." % (year, babies_born)
        elif choice == 5:
            quit = True

##################################################
            
def menu():
    """
    Presents the user with a menu and returns the valid selection.
    """

    print """
What would you like to do?
1. Count how many babies were born in a specific year.
2. Count how many people had a specific name in the entire database.
3. Count how many boys or girls had a specific name in a specific year.
4. Find the most popular boy or girl name for a specific year.
5. Quit.
"""
    
    return valid_int("Your choice? ", 1, 5)


##################################################

def valid_int(prompt, low, high):
    """
    Print the prompt provided and have the user enter a value. Be sure
    to validate the user input so only integers between low and high
    (inclusive) are accepted.

    For example, if you call the function like this:
       valid_int("Pick a number between 1 and 10: ", 1, 10)

    Then in this example, the user will see on the screen
    "Pick a number between 1 and 10: "
    and you will make sure that the answer returned from this function is
    always an int between 1 and 10.
    """

    # You need to add code to complete this function. Until you do,
    # this function always returns 5.
 
    return 5  # You need to replace this line when you write this function

##################################################

def valid_sex():
    """
    Prompt the the user to enter either "M" or "F". Be sure to validate the
    user input so only "M" or "F" are accepted.
    """
    
    # You need to add code to complete this function. Until you do,
    # this function always returns "F"

    return "F"  # You need to replace this line when you write this function

##################################################

def babies_born_in(data, year):
    """
    Given the data set and a specific year, return the number of babies
    born in that year, regardless of name or sex.
    """
    
    # You need to add code to complete this function. Until you do,
    # this function always returns 1000

    return 1000  # You need to replace this line when you write this function

##################################################

def babies_with_name(data, name):
    """
    Given the data set and a specific name, return the total number of babies
    born with that name, regardless of the year or the sex of the baby.
    """

    # You need to add code to complete this function. Until you do,
    # this function always returns 50

    return 50  # You need to replace this line when you write this function


##################################################

def babies_with_name_in_year_by_sex(data, name, year, sex):
    """
    Given the data set and a specific name, year, and sex, return
    the number of babies born in that year who had that name and sex.
    """

    # You need to add code to complete this function. Until you do,
    # this function always returns 10

    return 10  # You need to replace this line when you write this function

##################################################

def most_popular_name(data, year, sex):
    """
    Given the data set, a specific year, and a sex, report the most
    popular name for that year and sex.
    """
    
    # You need to add code to complete this function. Until you do,
    # this function always returns "DYLAN"

    return "DYLAN"  # Replace this line when you write this function

##################################################
##    DO NOT CHANGE ANYTHING BELOW THIS LINE    ##
##################################################

def read_names():
    """
    ** DO NOT CHANGE THIS FUNCTION **

    Reads the names from a file and returns a list of lists.
    Each list inside the big list is contains a year, name, sex, and count.
    For example:
      [2011,'RICHARD','M',175]

    ** DO NOT CHANGE THIS FUNCTION **
    """
    namefile = open('names.csv')
    names = []
    for row in namefile.readlines():
        (year, name, sex, count) = row.split(',')
        names.append([int(year), name, sex, int(count)])

    return names



main()
