随机生成验证码2
用for循环的随机码
1 import random 2 3 str1 = '' 4 for i in range(4): 5 # 验证码为四位 6 i1 = random.randint(0,3) 7 if i1 == i: 8 # 随机生成字母 9 cur = chr(random.randint(65, 90)) 10 else: 11 # 随机生成数字 12 cur = str(random.randint(0, 9)) 13 str1 += cur 14 15 print(str1)