# Compute and display the median of a collection of values entered by the # user. # Create a new, empty list data = [] # Read the first value from the user value = input("Enter a value (blank line to quit): ") # While the input is not the empty string while value != "": # Convert the input entered by the user from a string to a float value = float(value) # Insert the value at the front of the list data.insert(0, value) # Read the next input from the user value = input("Enter the next value (blank line to quit): ") # Sort the list data.sort() # If no values were entered if len(data) == 0: print("No values were entered.") # If the length of the list is odd elif len(data) % 2 == 1: # Compute the median as the middle element in the list median = data[len(data) // 2] # Display the result print("The median of those values is", median) else: # Compute the median as the average of the middle two elements median = (data[len(data) // 2] + data[len(data) // 2 - 1]) / 2 # Display the result print("The median of those values is", median)