Python program to calculate Median Using List

Write a python program to calculate Median using List.

01. Method

def findMedian(mList):
    mList.sort()
    print ('Sorted List: ', mList)
    if len(mList) % 2 == 0:
        n = mList[len(mList) // 2] + mList[len(mList) // 2 + 1]
        print ('Median: ', n / 2)
    else:
        print ('Median: ', mList[len(mList) // 2])
  
dataList = [60, 120, 130, 140, 150, 70, 80, 90, 100, 110,111,112]
findMedian(dataList)

Output:

Sorted List:  [60, 70, 80, 90, 100, 110, 111, 112, 120, 130, 140, 150]
Median:  111.5

Related Posts:

  1. Python program to find largest among three numbers
  2. Python program to calculate Mean using List
  3. Python program to calculate Mode using List

Leave a comment