This article mainly introduces Python to verify the enterprise's industrial and commercial registration code. if you need it, you can refer to the first six digits of the Chinese Enterprise's industrial and commercial registration code as the administrative code and the eight digits in the middle of the code, the last digit is the verification code calculated based on the ISO 7064: 1983.MOD 11-2 verification code. this algorithm determines whether the enterprise registration code is valid based on the algorithm of the last verification code, A slight modification can also be used to determine whether other verification codes are correct.
Checknum. py
# Coding: utf-8def getchecknum (input): # define the enterprise registration code verification code calculation function 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' enter the company's 15-digit registration code :') while True: try: len (code) = 15 num = code [: 14] check_num = int (code [14]) if check_num = int (getchecknum (num )): print U' congratulations, the registration code is correct. 'Else: print U' please note that this registration code is incorrect !!! 'Break failed t: print u "Please enter the correct enterprise 15-digit registration code" raw_input (u' press any key to exit ')