Skip to content

Instantly share code, notes, and snippets.

@vishalkanaujia
Created February 14, 2019 04:57
Show Gist options
  • Save vishalkanaujia/e49aa078131e9a5de0f25bbfd246a046 to your computer and use it in GitHub Desktop.
Save vishalkanaujia/e49aa078131e9a5de0f25bbfd246a046 to your computer and use it in GitHub Desktop.
import sys
def isNumber(s):
for i in range(len(s)):
┆ if s[i] == '-':
┆ ┆ try:
┆ ┆ ┆ if not s[i+1].isdigit():
┆ ┆ ┆ ┆ return False
┆ ┆ except Exception:
┆ ┆ ┆ return False
┆ if ord(s[i]) >= 48 and ord(s[i]) <= 57:
┆ ┆ return True
return False
sum = 0
# It reads three input lines from stdin
# and finds cumulative abs sum of only numbers
for i in range(3):
line = sys.stdin.readline()
x = isNumber(line.strip())
print x
if x:
┆ sum += abs(int(line.strip()))
print(sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment