-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplus-minus.py
More file actions
41 lines (32 loc) · 750 Bytes
/
Copy pathplus-minus.py
File metadata and controls
41 lines (32 loc) · 750 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
#!/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
n = len(arr)
neg = 0
pos = 0
zero = 0
#traverse through the list
for i in arr:
if i < 0:
neg += 1 #inc if negative
if i > 0:
pos += 1 #inc if positive
if i == 0:
zero += 1 #inc if zero
print("{:.6f}".format(pos/n))
print("{:.6f}".format(neg/n))
print("{:.6f}".format(zero/n))
if __name__ == '__main__':
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
plusMinus(arr)