• + 0 comments
    def find_median(arr):
        n = len(arr)
        if n % 2 == 1:
            return arr[n // 2]
        else:
            return (arr[n // 2] + arr[n // 2 - 1]) / 2
    
    def interQuartile(values, freqs):
        expanded_data = []
        for i in range(len(values)):
            expanded_data.extend([values[i]] * freqs[i])
        expanded_data.sort()
        q2 = find_median(expanded_data)
        n = len(expanded_data)
        if n % 2 == 1:
            lower_half = expanded_data[:n // 2]  
            upper_half = expanded_data[n // 2 + 1:]  
        else:
            lower_half = expanded_data[:n // 2]  
            upper_half = expanded_data[n // 2:]  
        q1 = find_median(lower_half)
        q3 = find_median(upper_half)
        iqr = q3 - q1
        print(f"{iqr:.1f}")