Skip to content

Instantly share code, notes, and snippets.

@filletofish
Created December 21, 2016 13:10
Show Gist options
  • Save filletofish/39155a6f29f6c2fca6af9d4d61e0e5bb to your computer and use it in GitHub Desktop.
Save filletofish/39155a6f29f6c2fca6af9d4d61e0e5bb to your computer and use it in GitHub Desktop.
def my_int(x):
if len(x) == 0:
return -1
res = 0
exp = len(x) - 1
for c in x:
digit = ord(c) - ord('0')
if digit < 0 or digit > 9:
return -1
else:
res += digit * (10 ** exp)
exp -= 1
return res
num = input("-> ")
print(my_int(num))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment