# Compute the mode of a list of values entered by the user # Read all of the values from the user and store them in a list # A blank line will be used to mark the end of input data = [] line = input("Enter a value (blank line to exit): ") while line != "": data.append(line) # Read the next input value line = input("Enter a value (blank line to exit): ") # Create a new, empty dictionary counts = {} # For each item in the list for item in data: # If the item is already present in the dictionary if item in counts.keys(): # Increase its count by 1 counts[item] = counts[item] + 1 # Otherwise else: # Add it to the dictionary with a count of 1 counts[item] = 1 # If there were values entered if len(data) > 0: # Find the key in the dictionary with the largest value and display the result largest_value = max(counts.values()) # List all of the keys that have a value equal to largest_value print("The mode or modes of the list is/are:") for item in counts.keys(): if counts[item] == largest_value: print(item) else: # Display an appropriate message if no values were entered print("No values were entered.")