使用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('<身份证不合法>')

百度网盘真是太讨厌了,链接总是失效。
直接上传到百度文库好了。。。

地址:http://wenku.baidu.com/view/4be42951eff9aef8951e062f.html

生成’泡菜’方法:

city = {'110000':'北京市',
        '110100':'北京市市辖区',
        ...
       }
import pickle
pickle_file = open('cityid_data.pkl', 'wb')
pickle.dump(city, pickle_file)
pickle_file.close()

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

posted on 2014-07-28 13:22  卖火柴的小东东  阅读(2017)  评论(0编辑  收藏  举报

导航