Plus Minus

  • + 0 comments

    !/bin/python3

    import math import os import random import re import sys

    #

    Complete the 'plusMinus' function below.

    #

    The function accepts INTEGER_ARRAY arr as parameter.

    #

    def plusMinus(arr): pos_num = 0 neg_num = 0 zero_num = 0

    iterate over array

    for num in arr:
        if num > 0:
            pos_num += 1
        elif num < 0:
            neg_num += 1
        else:
            zero_num += 1
    

    Calculate totals

    total = len(arr)
    pos_ratio = pos_num/total
    neg_ratio = neg_num/total
    zero_ratio = zero_num/total
    

    Print totals

    print("{:.6f}".format(pos_ratio))   
    print("{:.6f}".format(neg_ratio))
    print("{:.6f}".format(zero_ratio))   
    

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

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