python3 随机生成6位数的验证码
要求是数字:0~9 及大小写字母。
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Hiuhung Wan
import random
# 48--57 : 0-9
# 65--90 : A-Z
# 97--122: a-z
index = 6
count = 0
str1 = ‘‘ #存放验证码
while index > count:
num = random.randrange(48,122)
if (num <= 57) or (num >= 65 and num <= 90) or (num >= 97): #符合条件
str1 += chr(num)
count += 1
print(str1)
效果如下
C:\Python36\python.exe D:/Py/1704/day04/随机验证码.py YpEDP0 Process finished with exit code 0
原文:https://www.cnblogs.com/hiuhungwan/p/9210890.html