# # Compute the mode for a collection of values entered by the user. # # # Read all of the values from the user and store them in a list. # values = [] line = input("Enter the first value (blank to quit): ") while line != "": values.append(line) line = input("Enter the next value (blank to quit): ") # # Identify the count for each item that appeared in the list # # Create a new, empty dictionary where the keys are items in the list and # the values are the counts. counts = {} # For every item in the list... for item in values: # If it's an item that has been seen before... if item in counts.keys(): # Increase the count for the current item counts[item] = counts[item] + 1 else: # Add the item as a key in the dictionary with a count of 1 counts[item] = 1 print(counts)