| •1 |
#!/usr/bin/python3 |
| 2 |
|
| 3 |
# Python program to sum many large integers separated by spaces or newlines. |
| 4 |
# The integers to sum may be entered on the command-line or into standard input. |
| 5 |
|
| 6 |
import string |
| 7 |
import sys |
| 8 |
|
| 9 |
sum = 0 # initialize sum and make it an integer |
| 10 |
args = sys.argv[1:] |
| 11 |
if (args == []): |
| 12 |
# read stdin if no command line args |
| 13 |
while True: |
| 14 |
try: |
| •15 |
input_line = input() |
| 16 |
except: |
| 17 |
break; |
| •18 |
for s in input_line.split(): |
| 19 |
sum += int(s) |
| 20 |
else: |
| 21 |
# sum together the command-line args |
| 22 |
for arg in args: |
| 23 |
sum += int(arg) |
| •24 |
print(sum) |