-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswer.py
More file actions
37 lines (29 loc) · 832 Bytes
/
answer.py
File metadata and controls
37 lines (29 loc) · 832 Bytes
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
import fileinput
import sys
def summation(lines: str) -> int:
sum = 0
for line in lines:
# translate to int values
value = int(line)
#stops when encounter -999
if(value == -999):
break
#ignores negative numbers
if(value < 0):
continue
#summates
else:
sum += value
if(sum == 0): #returns empty if there are no values
return 'EMPTY'
return sum
if __name__ == "__main__":
# Get the filename from stdin
filename = input()
#print(filename)
# Open the file and read in its contents
with open(filename) as data_file:
number_of_lines = data_file.readline() #read first line- quantity
lines = data_file.readlines()
# Actually do the work
print(summation(lines))