統(tǒng)一社會信用代碼校驗位python實現(xiàn)

18位統(tǒng)一代碼最后一位計算方法如下:

```

def unioncode_checknum(code):

? ? alpha_to_num_map={'A':10,'B':11,'C':12,'D':13,'E':14,'F':15,'G':16,'H':17,'J':18,'K':19,'L':20,'M':21,'N':22,'P':23,'Q':24,'R':25,'T':26,'U':27,'W':28,'X':29,'Y':30}

? ? num_to_alpha_map={}

? ? for k,v in alpha_to_num_map.items():

? ? ? ? num_to_alpha_map[v]=k


? ? print(num_to_alpha_map)

? ? weights = [1,3,9,27,19,26,16,17,20,29,25,13,8,24,10,30,28]


? ? total = 0

? ? for i in range(len(code)):

? ? ? ? c = code[i]

? ? ? ? if?not?c.isdigit():

? ? ? ? ? ? total+=alpha_to_num_map[c]*weights[i]

? ? ? ? else:

? ? ? ? ? ? total+=int(c)*weights[i]

? ? pos = 31-(total%31)

? ? if pos==31:

? ? ? ? return 0

? ? if pos<10:

? ? ? ? return pos

? ? else:

? ? ? ? return num_to_alpha_map[pos]


```

統(tǒng)一社會信用代碼定義:

http://www.bjdm.org.cn/userfiles/file/1513058211657.pdf

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容