n1 = '10' nums = '64630 11735 14216 99233 14470 4978 73429 38120 51135 67060' n1 = '12' nums = '3 5 5 7 8 12 13 14 15 18 21 22' # Enter your code here. Read input from STDIN. Print output to STDOUT #n1 = raw_input() #nums = raw_input() import itertools import math numbers = sorted(map(lambda x: int(x), nums.split())) n = len(numbers) #print numbers def myprint(x): print( '%1.0f' % x) def median(numbers): n = len(numbers) mid1 = int(math.floor((n-1)/2)) mid2 = int(math.ceil(n/2)) #median return ((numbers[mid1] + numbers[mid2]) / 2.0 ) splitsize = int(math.floor((n)/2) ) #printit myprint (median(numbers[:splitsize]) ) myprint (median(numbers)) myprint (median(numbers[-splitsize:]) )
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question