Python statistics.median_low() Method with Examples

statistics.median_low() Method in Python:

The statistics.median_low() method computes the data set’s low median. Before calculating the low median, the data is also sorted in ascending order using this method.

Note: It should be noted that if the number of data values is odd, it will return the exact middle value. If there are an even number of data values, it returns the smaller of the two middle values.

Syntax:

statistics.median_low(data)

Parameters

data: This is Required. It is the data values that will be used (it can be any sequence, list, or iterator).

Note: It is to be noted that if the data is empty, it returns a StatisticsError.

Return Value:

Returns a float value representing the data’s low median (middle value).

Examples:

Example1:

Input:

Given list = [10, 20, 40, 15, 30, 13, 17]

Output:

The low median of the given list items [10, 20, 40, 15, 30, 13, 17] =  17

Example2:

Input:

Given list = [2, 1, 3, 5, 7, 8]

Output:

The low median of the given list items [2, 1, 3, 5, 7, 8] = 3

statistics.median_low() Method with Examples in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import statistics module using the import keyword.
  • Give the list as static input and store it in a variable.
  • Pass the given list as an argument to the statistics.median_low() method that computes the low median of the given list items.
  • Store it in another variable.
  • Print the low median of the given list items.
  • The Exit of the Program.

Below is the implementation:

# Import statistics module using the import keyword.
import statistics
# Give the list as static input and store it in a variable.
gvn_lst = [10, 20, 40, 15, 30, 13, 17]
# Pass the given list as an argument to the statistics.median_low() method that
# computes the low median of the given list items.
# Store it in another variable.
rslt = statistics.median_low(gvn_lst)
# Print the low median of the given list items.
print("The low median of the given list items", gvn_lst, "= ", rslt)

Output:

The low median of the given list items [10, 20, 40, 15, 30, 13, 17] =  17

Method #2: Using Built-in Functions (User Input)

Approach:

  • Import statistics module using the import keyword.
  • Give the list as user input using list(),map(),input(),and split() functions.
  • Store it in another variable.
  • Pass the given list as an argument to the statistics.median_low() method that computes the low median of the given list items.
  • Store it in another variable.
  • Print the low median of the given list items.
  • The Exit of the Program.

Below is the implementation:

# Import statistics module using the import keyword.
import statistics
# Give the list as user input using list(),map(),input(),and split() functions.
# Store it in a variable.
gvn_lst = list(map(int, input(
    'Enter some random List Elements separated by spaces = ').split()))

# Pass the given list as an argument to the statistics.median_low() method that
# computes the low median of the given list items.
# Store it in another variable.
rslt = statistics.median_low(gvn_lst)
# Print the low median of the given list items.
print("The low median of the given list items", gvn_lst, "= ", rslt)

Output:

Enter some random List Elements separated by spaces = 2 1 3 5 7 8
The low median of the given list items [2, 1, 3, 5, 7, 8] = 3