The challenge is
Given an array of integers, calculate the fractions of its elements that are positive, negative, and are zeros. Print the decimal value of each fraction on a new line.
This is my code for it:
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the plusMinus function below.
def plusMinus(arr):
l = len(arr) #get length of the array
p = 0 #positive ints
n = 0 # negative ints
z = 0 # zeroes
for i in range(0, len(arr)):
if arr[i] > 0: #check if num is positive
p = p+1
elif arr[i] < 0: #check if num is negative
n = n+1
else: z = z+1 #check if num is zero
return p/l, n/l, z/l
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().rstrip().split()))
plusMinus(arr)
For some reason it says that my output is
~ no response on stdout ~
So I tried putting the function inside a print function like that:
print(plusMinus(arr))
And it does output the correct answers to the challenge, but I'm guessing it's not the right format hackerrank expects, it says the output is:
(0.5, 0.3333333333333333, 0.16666666666666666)
instead of:
0.500000 0.333333 0.166667
What am I doing wrong? thanks in advance.