Skip to content

Instantly share code, notes, and snippets.

@ababycat
Last active May 16, 2020 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ababycat/f3c02b0b134854caf663a9c879fb5fbe to your computer and use it in GitHub Desktop.
Save ababycat/f3c02b0b134854caf663a9c879fb5fbe to your computer and use it in GitHub Desktop.
Id card.
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