Python随机生成一个六位数的验证码

import random
str = ""
str1 = ""
list = []
index = 0
num = 0
while num < 6:
    x = random.choice(range(12))   # 对随机生成的字符进行随机排序
    if x < 4:
        list.append(chr(random.choice(range(10)) + 48))   #随机生成一个字符0—9
    elif x < 8:
        list.append(chr(random.choice(range(65, 90))))    #随机生成一个字符A—Z
    else:
        list.append(random.choice(chr(random.choice(range(97, 122))))) #随机生成一个字符a—z
    num += 1
while index < 6:
    str1 = list[index]
    str += str1
    index += 1
print(str)

猜你喜欢

转载自blog.csdn.net/yihong_li/article/details/81120857