失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python编写个人信息查询_使用Python改写的身份证信息查询小程序

python编写个人信息查询_使用Python改写的身份证信息查询小程序

时间:2019-12-08 02:20:28

相关推荐

python编写个人信息查询_使用Python改写的身份证信息查询小程序

花了几天时间过了一遍python基础。真心感觉python让世界充满了爱…

先简单的使用一下python好了,拿以前写的《C语言身份证信息查询系统(修改版)》开刀~

很多东西,不需要考虑C语言的细节问题了,很多封装好的功能。方便好多。代码也自然少了好多。

python的‘泡菜’功能也是相当的棒!

import pickle

pickle_file = open('cityid_data.pkl', 'rb')

city = pickle.load(pickle_file)

str = input('请输入身份证号码:')

cid = str[:6]

birth = str[6:14]

cname = city[cid]

num = int(str[1])

tmpsum = int(str[0])*7 + int(str[1])*9 + int(str[2])*10 + int(str[3])*5 + int(str[4])*8 \

+ int(str[5])*4 + int(str[6])*2 + int(str[7])*1 + int(str[8])*6 + int(str[9])*3 \

+ int(str[10])*7 + int(str[11])*9 + int(str[12])*10 + int(str[13])*5 \

+ int(str[14])*8 + int(str[15])*4 + int(str[16])*2;

remainder = tmpsum % 11

sex = int(str[16]) % 2

if sex == 1:

sex = '男'

else :

sex = '女'

maptable = {0: '1', 1: '0', 2: 'x', 3: '9', 4: '8', 5: '7', 6: '6', 7: '5', 8: '4', 9: '3', 10: '2'}

if maptable[remainder] == str[17]:

print('')

print('性别:' + sex)

print('出生日期:' + birth)

print('归属地:' + cname)

else :

print('')

百度网盘真是太讨厌了,链接总是失效。

直接上传到百度文库好了。。。

生成’泡菜’方法:

city = {'110000':'北京市',

'110100':'北京市市辖区',

...

}

import pickle

pickle_file = open('cityid_data.pkl', 'wb')

pickle.dump(city, pickle_file)

pickle_file.close()

之后,把生成的cityid_data.pkl和上面的python程序放在一起运行就妥妥的了。

如果觉得《python编写个人信息查询_使用Python改写的身份证信息查询小程序》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。