Created
January 28, 2019 03:26
-
-
Save imilas/9637153fcb6a5076c25f2e22cb16311b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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