• [deleted]
    + 0 comments
    def interQuartile(values, freqs):
        # Print your answer to 1 decimal place within this function
        arr=[]
        for i in range(len(values)):
            ans = [values[i]] * freqs[i]  
            arr.extend(ans)  
        arr.sort()
        
        n = len(arr)
        mid = n//2
        
        if n%2 == 0:
            L = arr[:mid]
            U = arr[mid:]
        else:
            L = arr[:mid]
            U = arr[mid+1:]
        
        Q1 = median(L)
        Q3 = median(U)
        
        answer = Q3-Q1
        print(f"{answer:.1f}")
        
    def median(a):
        n = len(a)
        mid = n//2
        if n % 2 == 0:
            median = (a[mid] + a[~mid]) / 2
        else:
            median = a[mid]
            
        return round(median)