-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplus-minus
42 lines (32 loc) · 834 Bytes
/
plus-minus
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
#!/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):
listaPositivos = []
listaNegativos = []
listaZeros = []
lista = arr
n = len(lista)
for elemento in lista:
if elemento > 0:
listaPositivos.append(elemento)
elif elemento < 0:
listaNegativos.append(elemento)
else:
listaZeros.append(elemento)
nP = len(listaPositivos)
nN = len(listaNegativos)
nZ = len(listaZeros)
print(format(nP/n, '.6f')+'\n', format(nN/n, '.6f')+'\n', format(nZ/n, '.6f'))
if __name__ == '__main__':
n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
plusMinus(arr)