Advertisement
farhansadaf

Median

May 7th, 2018
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. lst = []
  2. n = int(input())
  3. i = 0
  4. while (i<n):
  5.     a = int(input())
  6.     lst.append(a)
  7.     if len(lst) is 1:
  8.         print(lst[0])
  9.     else:
  10.         lst.sort()
  11.         if len(lst)%2 == 0:
  12.             print((lst[len(lst)//2] + lst[len(lst)//2 - 1]) // 2)
  13.         else:
  14.             print(lst[len(lst) // 2])
  15.     i+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement