For a list of real numbers, their median is defined as the number in the middle after sorting them from smallest to largest. For example, if there are numbers (e.g., 6, 8, 1000), after sorting the median is 8. If there are an even number of numbers (e.g., 6, 8, 81, 1000), the median is the average of the middle two numbers, which is (6 + 8) / 2 = 7.
Compared to the mean of a sample, the median is usually a better measure of the center. This is because the median is robust to outliers, such as the number 1000 in the example above.
Write a Python program that, given a list of numbers, will print their median. Your program will ask for the list as user input, where the list will be entered with commas in between without any spaces. For example, your program needs to print the median for the user input 4, 8, 6.
NOTE: You may not use Numpy or any other modules for this question. You will need to solve this question by using only base Python.
HINT: In Python, you can sort a list using the sorted() function. You can find more information here.
# get the user input string
input_string = input("Enter a list of numbers separated by commas: ")
# split the user input string into a list
input_string_splitted = input_string.split(",")
# convert the list elements from string to float using list comprehension
numbers = [float(element) for element in input_string_splitted]
## ADD YOUR CODE BELOW
median = 0
## ADD YOUR CODE ABOVE
print(f"The median is: {median:.2f}")