Verify the enterprise registration code using Python

Source: Internet
Author: User
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 ')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.