Created
March 28, 2020 07:05
-
-
Save raszia/9cbdc2ef265be88f4564a5aedf444555 to your computer and use it in GitHub Desktop.
Generate a valid and random iranian meli code
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
#!/usr/bin/python3 | |
import random | |
import sys | |
def meli_code_generator(): | |
while True: | |
meli_code = random.sample(range(1, 10), 9) | |
place_list = [10,9,8,7,6,5,4,3,2] | |
x = 0 | |
for (a, b) in zip(place_list, meli_code): | |
x = x + (a*b) | |
remainder = (x % 11) | |
if x < 2: | |
last_number = remainder | |
elif x >= 2: | |
last_number = (11 - remainder) | |
if last_number < 10: | |
listToStr = ' '.join([str(number) for number in meli_code]) | |
print(listToStr.replace(" ","")+str(last_number)) | |
break | |
else: | |
pass | |
if __name__ == "__main__": | |
meli_code_generator() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generate a valid and random iranian meli code
ساخت کد ملی معتبر به صورت اتفاقی
python meliGenerator.py