-
-
Save Alireza2n/5708c361ca8417dec0f355d8eb51bc2b to your computer and use it in GitHub Desktop.
تولید کننده کد ملی در پایتون
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def national_code_generator(): | |
number_list = [] | |
_sum = 0 | |
out = "" | |
for i in reversed(range(2, 11)): | |
_j = random.randint(0, 9) | |
number_list.append(str(_j)) | |
_sum += _j * i | |
_m = _sum % 11 | |
if _m < 2: | |
number_list.append(str(_m)) | |
elif _m >= 2: | |
number_list.append(str(11 - _m)) | |
return out.join(number_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
برای استفاده در کاربرد های تست اپ ها
unit test, factory_boy, etc.
با تشکر از http://kpnu-csc.ir/forum/-php/3255-a-post12409.html#post12409