#boxandwhisker #it creates a box and whiskers plot of the numbers you entered def findMedian (a) : length = len(a) if length % 2 == 0: #even add the two middle numbers and divide by two lowerMiddle = a [length//2-1] upperMiddle = a [length//2] m = (lowerMiddle+upperMiddle)/ 2.0 return m else: m = a [length// 2] return m # [1,2,3,4,5,6,7,8,9,10] alist = [10,9,8,7,6,5,4,3,2,1] print ("Your list is unsorted.", alist) print ("Here is your data set:" , end="") alist.sort () dataSet = alist print (dataSet) lowerExtreme = dataSet [0] upperExtreme = dataSet [-1] print ("Lower Extreme:", lowerExtreme) print ("Higher Extreme:", upperExtreme) median = findMedian(dataSet) print ("Median:", median) length = len(alist) print ("The orginal list has this many items:", length) #even list if length%2==0: lower = alist[: length//2] lq = findMedian(lower) #print ("Lower,", lower) upper = alist[length//2:] uq = findMedian (upper) #print ("Upper", upper) else: #odd list lower = alist [:length //2] lq = findMedian(lower) #print ("Lower,", lower) upper = alist[length //2+1: ] uq = findMedian(upper) #print ("Upperr,", upper) print ("Lower quartile:", lq ) print ("Upper quartile:", uq )
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