Created
December 21, 2016 13:10
-
-
Save filletofish/39155a6f29f6c2fca6af9d4d61e0e5bb 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
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