• + 0 comments

    `Packages Used

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    
    def median(x):
        x = sorted(x)
        length = len(x)
        if length % 2 == 0: 
            half_length = (length // 2)
            median = (x[half_length - 1] + x[half_length]) / 2
        else:   
            half_length = length // 2
            median = x[half_length]
        return median
        
    def mean(x):
        length = len(x)
        return sum(x) / length
        
        
    def mode(x):
        counter = {}
        for val in x:
            counter[val] = counter.get(val, 0) + 1
        
        max_frequency = max(counter.values())
        modes = [k for k, v in counter.items() if v == max_frequency]
        
        # If multiple elements have the same max frequency, return the smallest one
        return int(min(modes))
            
    def std(x):
        x_mean = mean(x)
        x_std = (sum(((val - x_mean) ** 2 for val in x)) / len(x)) ** 0.5
        return x_std
            
    
    def confidence_interval(x):
        x_mean = mean(x)
        x_std = std(x)
        length = len(x)
        interval = 1.96 * (x_std / (length ** 0.5))
        
        lower, upper = x_mean - interval, x_mean + interval
        
        return lower, upper, 1
    
    if __name__ == '__main__':
    
        length = input()
        values = [float(val) for val in input().split(" ")]
        print(mean(values))
        print(median(values))
        print(mode(values))
        print(round(std(values), 1))
        print(round(confidence_interval(values)[0], 1), round(confidence_interval(values)[1], 1))