ubuntu2004
# TODO Make the month_names list from the months module available1from months import month_names23# TODO Make the sort_by_month function from the months module4# available as sort_by_month_name56# Make the matplotlib module available7import matplotlib89# Set up rendering of matplotlib so that it doesn't try to10# display the plot11matplotlib.use('Agg')1213# Make the plotting functions of matplotlib available14import matplotlib.pyplot as plt1516# Ask the user for how many people are in the class, storing the17# number entered into an integer variable named number_of_students18number_of_students = int(raw_input('How many people are in the class? '))1920# Initialize a variable named number_entered to keep of how many people we have entered21number_entered = 02223# Initialize an empty dictionary named month_counts24month_counts = dict()25people_by_month = dict()2627# TODO Set the value associated with each month in months_names to 0 in the28# dictionary named month_counts29for month in month_names:30month_counts[month] = 031people_by_month[month] = list()3233# As long as there are more people34# TODO: Fill in a comparison of number_entered with number_of_students35while number_entered < number_of_students:36# Ask for the next person's birthdate37line = raw_input('Enter name and birthday, separated by comma: ')3839# TODO Split up the line into parts, separated by the , character, storing the40# result into a list named name_and_birthday41name_and_birthday = line.split(',')42print "The name is ", name_and_birthday[0], 'and birthday is', name_and_birthday[1]4344# TODO Strip off any spaces from the birthday portion of name_and_birthday, then45# split based on a space, storing the two parts into a list named46# month_and_day47month_and_day = name_and_birthday[1].strip(' ').split(' ')4849# TODO Set the variable "month" to be the 3 letter abbreivation, which is50# one of the elements in the list named month_and_day51month = month_and_day[0]5253# TODO Increment the number of people whose birthdays we've entered, which54# is in the variable number_entered55number_entered += 15657# TODO Increment the value in the month_count dictionary for this month58month_counts[month] += 159people_by_month[month].append(name_and_birthday[0])6061# Get out the x_values, which are the month names62x_values = month_names6364# Create a list of the y-values from the month_counts dictionary, in the same order as the values in the months_names65# list66y_values = list()67for month in month_names:68y_values.append(month_counts[month])6970# Create a plot object with formatting specifying no line,71# just circles, for the values in x_values and y_values72plt.plot(x_values, y_values, 'ro')7374# Save that plot to the file months-dictionary.png75plt.savefig('months-dictionary-wednesday-3.png')7677for month in month_names:78if len(people_by_month[month]) > 0:79print month, people_by_month[month]80else:81print month, ": no one born in", month8283