I have a program where it's supposed to get how much snow did it fall in each month of the year, store it in a dictionary and print all of the data in the correct order. I also need to print the total of snow in the whole year.
this is what I have so far:

def main(): M=['January', 'February', 'March','April', 'May', 'June', 'July', 'August','September', 'October', 'November', 'December'] dic = {} for i in range(0, len(M)): theKeys = list(dic.items()) theKeys.sort() inpt = int(input("How much did it snow in " + str(M[i]) + " ?:")) dic[str(M[i])] = inpt theKeys = list(dic.items()) theKeys.sort() print(dic)main()This program ask the user for the snow in the correct order. However, when it prints everything, this is what I get:

How much did it snow in January ?:1How much did it snow in February ?:2How much did it snow in March ?:3How much did it snow in April ?:4How much did it snow in May ?:5How much did it snow in June ?:6How much did it snow in July ?:7How much did it snow in August ?:8How much did it snow in September ?:9How much did it snow in October ?:10How much did it snow in November ?:11How much did it snow in December ?:12{'June': 6, 'July': 7, 'January': 1, 'December': 12, 'March': 3, 'October': 10, 'September': 9, 'May': 5, 'August': 8, 'February': 2, 'April': 4, 'November': 11}Also, what function I can use to print the total amount of snow? sum()?My book doesn't really has a lot of information for dictionaries. Sorry if it's a really stupid question.


View Solution