Skip to content

Instantly share code, notes, and snippets.

@imilas
Created January 28, 2019 03:26
Show Gist options
  • Save imilas/9637153fcb6a5076c25f2e22cb16311b to your computer and use it in GitHub Desktop.
Save imilas/9637153fcb6a5076c25f2e22cb16311b to your computer and use it in GitHub Desktop.
total = 0
ng50=0
n50=0
cursor = 0
nums=[]
with open('l.txt', 'r') as inp, open('output.txt', 'w') as outp:
for line in inp:
try:
num = float(line)
total+=num
nums.append(num)
outp.write(line)
except ValueError:
print('{} is not a number!'.format(line))
# nums = nums.sort()
# print(sorted(nums))
for c in sorted(nums,reverse=True):
cursor+=c
if(cursor>=int(total/2)):
n50 = c
break
for c in sorted(nums,reverse=True):
cursor+=c
if(cursor>=4300000):
ng50 = c
break
# if()
print('Total of all numbers: {}'.format(total))
print('n50: {}'.format(n50))
print('ng50: {}'.format(ng50))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment