python生成验证码 您所在的位置:网站首页 六位验证码图片 python生成验证码

python生成验证码

2023-12-02 18:12| 来源: 网络整理| 查看: 265

验证码是随机生成的、包含多个大写字母、小写字母或数字的随机字符序列。要求编写程序,实现生成随机六位验证码的功能。 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 实验室设备网 版权所有