You are viewing a single comment's thread. Return to all comments →
import math import os import random import re import sys
#
def plusMinus(arr): pos_num = 0 neg_num = 0 zero_num = 0
for num in arr: if num > 0: pos_num += 1 elif num < 0: neg_num += 1 else: zero_num += 1
total = len(arr) pos_ratio = pos_num/total neg_ratio = neg_num/total zero_ratio = zero_num/total
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)
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all 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
Calculate totals
Print totals
if name == 'main': n = int(input().strip())