中国企业工商注册码前六位为行政区代码,中间8位顺序编码,最后一位为根据ISO 7064:1983.MOD 11-2校验码计算出来的检验码,本算法根据最后一位校验码的算法来判断企业注册码是否合法,同时稍作修改也可用于判断其他校验码是否正确
checknum.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#coding: utf-8 def getchecknum( input ): ##定义企业注册码校验码计算函数 n = 10 for num in range ( len ( input )): n = ( int ( input [num]) + n) % 10 if n = = 0 : n = 10 n = n * 2 % 11 if n = = 0 : s = 1 elif n = = 1 : s = 0 else : s = 11 - n return str (s) code = raw_input (u '请输入该企业15位注册码:' ) while True : try : len (code) = = 15 num = code[: 14 ] check_num = int (code[ 14 ]) if check_num = = int (getchecknum(num)): print u '恭喜你,注册码正确。' else : print u '请注意,该注册码错误!!!' break except : print u "请输入正确的企业15位注册码" raw_input (u '按任意键退出' ) |