-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlusMinus.py
More file actions
48 lines (37 loc) · 982 Bytes
/
PlusMinus.py
File metadata and controls
48 lines (37 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/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):
# Write your code here
size_of_arr = len(arr)
zero_numbers = 0
pos_numbers = 0
neg_numbers = 0
if size_of_arr == 0:
return
for x in arr:
if x == 0:
zero_numbers += 1
elif x > 0:
pos_numbers += 1
else: # x<0
neg_numbers += 1
pos_ratios = pos_numbers/size_of_arr
neg_ratios = neg_numbers/size_of_arr
zero_ratios = zero_numbers/size_of_arr
print("{:.6f}".format(pos_ratios))
print("{:.6f}".format(neg_ratios))
print("{:.6f}".format(zero_ratios))
return None
if __name__ == '__main__':
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
plusMinus(arr)