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
|
207 Discussions
|
Please Login in order to post a comment
typescript/javascript
console.log((arr.filter(el => el > 0).length/arr.length).toFixed(6)); console.log((arr.filter(el => el < 0).length/arr.length).toFixed(6)); console.log((arr.filter(el => el === 0).length/arr.length).toFixed(6));
**
def plusMinus(arr): n = len(arr) # Get the number of elements count_positive = sum(1 for x in arr if x > 0) # Count positive numbers count_negative = sum(1 for x in arr if x < 0) # Count negative numbers count_zero = sum(1 for x in arr if x == 0) # Count zeros
if name == 'main': n = int(input().strip()) # Read the number of elements arr = list(map(int, input().rstrip().split())) # Read the array elements