• + 0 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)