Skip to content

Instantly share code, notes, and snippets.

@mllopart
Created June 16, 2017 15:46
Show Gist options
  • Save mllopart/88b099d96278ea9e42e8cf7395241837 to your computer and use it in GitHub Desktop.
Save mllopart/88b099d96278ea9e42e8cf7395241837 to your computer and use it in GitHub Desktop.
Plus Minus Hackerrank
#!/bin/python3
'''
Given an array of integers, calculate which fraction of its elements are positive,
which fraction of its elements are negative, and which fraction of its elements are zeroes,
respectively. Print the decimal value of each fraction on a new line.
'''
import sys
n = int(input().strip())
arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
neg = 0
pos = 0
zer = 0
for numA in arr:
if numA > 0: pos += 1
if numA < 0: neg += 1
if numA == 0: zer += 1
print(str(format(round(pos/n,6),'.6f')))
print(str(format(round(neg/n,6),'.6f')))
print(str(format(round(zer/n,6),'.6f')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment