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.
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):
# Initialize counters for positive, negative, and zero elements
positive_count = 0
negative_count = 0
zero_count = 0
# Total number of elements
total_count = len(arr)
# Count the positive, negative, and zero elements
for num in arr:
if num > 0:
positive_count += 1
elif num < 0:
negative_count += 1
else:
zero_count += 1
# Calculate and print the ratios
print("{:.6f}".format(positive_count / total_count))
print("{:.6f}".format(negative_count / total_count))
print("{:.6f}".format(zero_count / total_count))
Plus Minus
You are viewing a single comment's thread. Return to all comments →
Here is the solution in python3
!/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): # Initialize counters for positive, negative, and zero elements positive_count = 0 negative_count = 0 zero_count = 0
if name == 'main': n = int(input().strip())