-1

I have a problem that one of the things i need to include is a subscript of median, but i have no clue what that means

I have tried most things but again i have no clue what subscript of median means.

def median(a):
    a=a.sort()
    a=len(a)/2
    return a

def main():
    print(median([3,1,2]))
    print(median([4,3,2,1]))
    print(median([1,5,3,2,4]))
    print(median([6,5,1,2,3,4]))

main()

I expect it to print out the median of the numbers if it gets two i need the lesser... We cant use average.

1 Answers1

0

You're returning the middle index, not the value of the element at that index.

Also, a.sort() modifies the list in place, it doesn't return the sorted list; a = a.sort() sorts the list and then sets a to None.

def median(a):
    s = sorted(a)
    middle = int(len(s)/2)
    return s[middle]

Barmar
  • 596,455
  • 48
  • 393
  • 495