Last active
May 16, 2020 03:02
-
-
Save ababycat/f3c02b0b134854caf663a9c879fb5fbe to your computer and use it in GitHub Desktop.
Id card.
This file contains hidden or 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 calcId(digit): | |
if not isinstance(digit, int) or len(str(digit)) != 17: | |
return False | |
table = '10X123456789' | |
alpha = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] | |
return table[sum([int(x)*a for x, a in zip(str(digit), alpha)]) % 11] | |
def isGoodId(instr): | |
if not isinstance(instr, str) or len(instr) != 18: | |
return False | |
number17 = 0 | |
try: | |
number17 = int(instr([0:17]) | |
except: | |
return False | |
return calId(number17) == instr[-1] | |
print(isGoodId('574642519050305044X')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment