Plus Minus

  • + 0 comments

    def plusMinus(arr): n = len(arr) # Get the number of elements count_positive = sum(1 for x in arr if x > 0) # Count positive numbers count_negative = sum(1 for x in arr if x < 0) # Count negative numbers count_zero = sum(1 for x in arr if x == 0) # Count zeros

    # Calculate ratios
    positive_ratio = count_positive / n
    negative_ratio = count_negative / n
    zero_ratio = count_zero / n
    
    # Print results with 6 decimal places
    print(f"{positive_ratio:.6f}")
    print(f"{negative_ratio:.6f}")
    print(f"{zero_ratio:.6f}")
    

    if name == 'main': n = int(input().strip()) # Read the number of elements arr = list(map(int, input().rstrip().split())) # Read the array elements

    plusMinus(arr)  # Call the function