Plus Minus

  • + 1 comment

    My code seems to work perfectly well on my machine for the same arrays as used in the test cases, but on Hackerrank they return erros. Anybody faced this before?

    def plusMinus(arr): n = len(arr) pos = 0 neg = 0 zero = 0

    for i in range(0,n):
        if arr[i]>0:
            pos +=1
        elif arr[i]<0:
            neg +=1
        elif arr[i]==0:
            zero +=1
    pos_ratio = pos/n
    neg_ratio = neg/n
    zero_ratio = zero/n
    print('positive ratio:', f'{pos_ratio:.6f}')
    print('negative ratio:', f'{neg_ratio:.6f}')
    print('zeros ratio:', f'{zero_ratio:.6f}')