-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplus_minus.py
42 lines (33 loc) · 908 Bytes
/
plus_minus.py
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
#https://www.hackerrank.com/challenges/one-month-preparation-kit-plus-minus/problem?isFullScreen=true&h_l=interview&playlist_slugs%5B%5D=preparation-kits&playlist_slugs%5B%5D=one-month-preparation-kit&playlist_slugs%5B%5D=one-month-week-one
#!/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
pos = 0
neg = 0
zero = 0
for i in arr:
if i > 0:
pos += 1
elif i == 0:
zero += 1
else:
neg += 1
lenA = len(arr)
pr = round(pos/lenA, 6)
nr = round(neg/lenA, 6)
zr = round(zero/lenA, 6)
print(pr, nr, zr, sep='\n')
if __name__ == '__main__':
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
plusMinus(arr)