Plus Minus

  • + 0 comments

    enumerate is slightly faster than for

    def plusMinus(arr): positives = 0 zeros = 0 negatives = 0 size = len(arr)

    for number arr:
        if number > 0 :
            positives += 1
        elif number == 0 :
            zeros += 1
        else:
            negatives += 1
    
    print(f'{positives/size:.6f}')
    print(f'{negatives/size:.6f}')
    print(f'{zeros/size:.6f}')
    

    if name == 'main': n = int(input().strip())

    arr = list(map(int, input().rstrip().split()))
    
    plusMinus(arr)