Python中位数计算求解答(列表)

img

l = list(map(int, input(">>>").split()))

l.sort()
if len(l) % 2 == 0:
    result = (l[len(l) // 2 -1] + l[len(l) // 2 ]) / 2
else:
    result = l[len(l) // 2]
    
print(result)