You are viewing a single comment's thread. Return to all comments →
def median(data): num = len(data) if num % 2 == 0: return (data[num//2 - 1] + data[num//2]) / 2 return data[(num-1) // 2] def quartiles(arr): n = len(arr) arrX = sorted(arr) Q2 = median(arrX) if n % 2 != 0: Q1 = median(arrX[:(n-1)//2]) Q3 = median(arrX[(n+1)//2:]) else: Q1 = median(arrX[:(n//2)]) Q3 = median(arrX[(n//2):]) return int(Q1), int(Q2), int(Q3)
Seems like cookies are disabled on this browser, please enable them to open this website
Day 1: Quartiles
You are viewing a single comment's thread. Return to all comments →