Median


#1

What wrong with my code, can't figure out:

def median(x):
    
    li = sorted(x)
    
    
    index1 = len(li) / 2
    index2 = len(li) / 2 - 1
    
    if len(li) % 2 == 0:
      return li[int(index1)] + li[int(index2)] / 2.0
    if len(li) % 2 != 0:
    
      return li[int(index1)]

Median
#2

order of operations, division comes before sum. so what is currently happening:

5 + 4 /2
5 + 2
7

you might want to use brackets or something


#3

Thanks! Can't understand - at my previous version of code there was braces, why I remove it - who knows.:confused: