# # Compute the median of a collection of values entered by the user. # # # Read all of the values from the user and store them in a list. # # Read the first value from the user line = input("Enter a number: ") # Create an empty list to store the values data = [] # While the user has not entered a blank line while line != "": # Convert the entered value to a floating point number num = float(line) # Add the number to the list of values data.append(num) # Read the next line from the user line = input("Enter a number: ") # # Sort the values. # data.sort() # # Report the median. # if len(data) == 0: # No values were entered print("The median cannot be computed because no values were entered.") elif len(data) % 2 == 0: # An even number of values were entered so the median is the average # of the two middle values median = (data[len(data) // 2] + data[len(data) // 2 - 1]) / 2 print("The median value is", median) else: # An odd number of values was entered so the median is the middle value median = data[len(data) // 2] print("The median value is", median)