出生自带靓号的天选之子

身份证校验规则——李永乐老师 包括验证方法以及计算最后一位的方法

# -*- coding:utf-8 -*-
"""
python2 运行 直接输入带x的身份证号会报语句错误,因为python2的input函数 在接受字符串输入时, 你必须用引号扩起来。
参见 https://www.runoob.com/python/python-func-input.html
"""
# while True:
#     id_num = str(input("请输入需要校验的身份证号码:"))
#
#     if id_num == 'q':
#         quit()
#
#     if len(id_num) != 18:
#         print("身份证号码为18位")
#         continue
#
#     check = 0
#     if id_num[0:17].isdigit():
#         for i in range(1, 19):
#             if id_num[17] == 'x':
#                 tmp = 10
#             else:
#                 tmp = int(id_num[18-i]) * (2**(i-1) % 11)
#             check += tmp
#         m = check % 11
#
#         if m == 1:
#             print("身份证校验正确。")
#             continue
#         else:
#             print("校验失败,身份证输入有误。")
#             continue
#
#     else:
#         print("身份证前17位为数字,请确认后重新输入。")
#         continue


# while True:
def compute_last_num(s):

    sum_compute = 0
    for i in range(2, 19):
        tmp_compute = int(s[18-i]) * (2 ** (i-1) % 11)
        sum_compute += tmp_compute
    a = (12 - sum_compute % 11) % 11
    if a == 10:
        a = 'x'
    return a


x = ["22020220200220", "22020220200222", "22020220200202"]
y = ["000", "222",
     "002", "020", '200',
     "022", "202", "220"]
for i in range(len(x)):
    for l in range(len(y)):
        s = x[i] + y[l]
        s += str(compute_last_num(s))
        tmp = True
        for index in s:
            if index != '2' and index != '0':
                tmp = False
        if tmp:
            print(s)