from random import randint
import os
def get_cretno(birthday):
for n in range(0, 36):
list=["110221", "120221", "130102", "140101", "150101", "210101", "210201", "220101",
"230101", "310101", "320101", "330101", "330201", "340101", "350101", "350201", "360101", "370101",
"370201", "410101", "420101", "430101", "440101", "440301", "450101", "460101", "500101", "510101",
"520101", "530101", "540101", "610101", "620101", "630101", "640101", "650101"
]
city=str(list[n])
#赋值生日
birthday = birthday
#三位随机数
a=''
for i in range(0,3):
a=a+str(randint(0,9))
cert1=city+birthday+str(a)
#最后一位校验码
calc=[7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
balc=['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
list1=[]
result=0
for j in cert1:
list1.append(j)
for k in range(len(list1)):
result+=(int(calc[k])*int(list1[k]))
lastnum=result%11
certno=cert1+balc[lastnum]
with open(r'd://身份证.txt','a') as f:
f.write(certno+'\n')
cn = get_cretno('19881126')