python生成验证码 | 您所在的位置:网站首页 › 六位验证码图片 › python生成验证码 |
验证码是随机生成的、包含多个大写字母、小写字母或数字的随机字符序列。要求编写程序,实现生成随机六位验证码的功能。 1.验证码共六位,需生成六个随机字符; 2.每次生成的随机字符需存储到某数据结构之中; 3.数据结构应具有可变、有序的特点。 import random code_list=[] for i in range(6): #控制验证码的位数 state=random.randint(1,3) #生成状态码 if state==1: first_kind=random.randint(65,90) #大写字母 random_uppercase=chr(first_kind) code_list.append(random_uppercase) elif state==2: second_kinds=random.randint(97,122) #小写字母 random_lowercase=chr(second_kinds) code_list.append(random_lowercase) elif state==3: third_kinds=random.randint(0,9) code_list.append(str(third_kinds)) verification_code="".join(code_list) print(verification_code)运行结果: |
CopyRight 2018-2019 实验室设备网 版权所有 |