'''
进行身份证信息的校验
输入前17位数,自动计算第18位数
'''
def jiaoyanma(shenfenzheng17):
def haoma_validate(shenfenzheng17):
if type(shenfenzheng17) in [str, list, tuple]:
if len(shenfenzheng17) == 17:
return True
raise Exception('Wrong argument')
if haoma_validate(shenfenzheng17):
if type(shenfenzheng17) == str:
seq = map(int, shenfenzheng17)
elif type(shenfenzheng17) in [list, tuple]:
seq = shenfenzheng17
t = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
s = sum(map(lambda x: x[0] * x[1], zip(t, map(int, seq))))
b = s % 11
bd = {
0: '1',
1: '0',
2: 'X',
3: '9',
4: '8',
5: '7',
6: '6',
7: '5',
8: '4',
9: '3',
10: '2'
}
return bd[b]
if __name__ == '__main__':
print(jiaoyanma('32048319950908561'))
网友评论