We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Plus Minus
- Discussions
Plus Minus
Plus Minus
Sort by
recency
|
297 Discussions
|
Please Login in order to post a comment
def plusMinus(arr): pos_num = 0 neg_num = 0 zeroes = 0 for i in arr:
TypeScript Solution
float[] valores = {0,0,0}; // plus, minus, 0 foreach(int x in arr) { valores[x > 0 ? 0 : x < 0 ? 1 : 2]++;
} Console.WriteLine(valores[0]/ arr.Count + "\n" + valores[1]/ arr.Count + "\n" + valores[2]/ arr.Count + "\n");
!/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 count_positive(a): return int(a > 0) def count_negative(a): return int(a < 0) def count_zero(a): return int(a == 0)
def plusMinus(arr): # Write your code here l = len(arr) p = sum(map(count_positive, arr)) n = sum(map(count_negative, arr)) z = sum(map(count_zero, arr)) print(f"{p/l:.6f}") print(f"{n/l:.6f}") print(f"{z/l:.6f}") if name == 'main': n = int(input().strip())