zoukankan      html  css  js  c++  java
  • python 身份证校验位计算

    以后可能用得到

    # -*- coding:gbk -*- 
    #
    S+=Sum(Ai*Wi);
    #
    Ti[S%11]
    import sys

    class IdentityCard:
        
    def __init__( self ):
            self.
    __Wi = [7910584216379105842]
            self.
    __Ti = ['1''0''x''9''8''7''6''5''4''3''2']

        
    def check( self, code ):
            
    if (len(code) != 17):
                
    print "必须为17位的字符"
                
    return False
            
    return True
            
        
    def calculate( self, code ):
            sum 
    = 0
            
    for i in range(17):
                sum 
    += int(code[i])*self.__Wi[i]
            
    return self.__Ti[sum%11]
            
    def test():
        ic 
    = IdentityCard()
        code 
    = "33000000000000000" #17位身份证
        if ic.check(code):
            
    print "你的校验位为:%s"%ic.calculate(code)
            
    if __name__ == '__main__':
        test()

  • 相关阅读:
    spring-ioc
    Hibernate之二级缓存
    hibernate之HQL语句
    hibernate 多对多关联关系
    hibernate关联关系(一对多)
    Hibernate之主键生成策略
    struts2的CRUD
    struts2的OGNL
    struts2的初步认识
    Maven介绍
  • 原文地址:https://www.cnblogs.com/Death/p/1993565.html
Copyright © 2011-2022 走看看