你好我想生成随机string.ascii_uppercase + string.digits的列表和我想要的代码如下:XXXXX-XXXXX-XXXXX(带有 - 的15个字符)和生成器询问你想要多少代码生成。谢谢你< 3
答案 0 :(得分:-1)
from random import choice
from string import ascii_uppercase, digits
CHAR_SET = ascii_uppercase + digits
def get_integer(msg):
while True:
try:
return int(input(msg))
except ValueError:
pass
def get_random_code(chunks=3, delim='-'):
def get_random_str(length=5):
return ''.join(choice(CHAR_SET) for _ in range(length))
return delim.join(get_random_str() for _ in range(chunks))
if __name__ == '__main__':
total_combos = get_integer('Enter # of combos to generate: ')
for _ in range(total_combos):
print(get_random_code())