Factor = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
Last = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2')
Last_dict = {}
sum = 0
idcard = input("请输入身份证号码:")
if len(idcard) == 18: # 判断身份证号码是否输入正确
for i in range(0, len(Factor)): # 通过循环将身份证号码前17位和系数对应相乘求总和
sum += int(idcard[i]) * Factor[i]
for i in range(0, 11): # 通过循环将身份证号码最后一位和对应的余数形成字典
Last_dict[i] = Last[i]
if str(Last_dict[sum % 11]) == str(idcard[17]):
print("身份证为真!")
if int(idcard[16]) % 2 == 1:
print("男性")
else:
print("女性")
else:
print("身份证非法!")
else:
print("身份证号码输入错误!")
python判断身份证真伪
最新推荐文章于 2024-03-10 15:11:47 发布