当前位置:   article > 正文

Python验证码简单实现(数字和大写字母组成的4位验证码)

python 筛选数字和字母组成的四位数据
#数字和英文大写字母的4位随机数
def checkcode(): #def 定义方法  checkcode() 方法名()
    import random # 导入包
    checkcode = ""
    string = range(0,4)
    for i in string:
        current = random.randrange(0,3) #randrange随机数  参数1<=随机数<=参数2
        if current != i:
            temp = chr(random.randint(65, 90))
        else:
            temp = random.randint(0,9)
        checkcode += str(temp)
    return checkcode #此方法返回值:checkcode(变量)
while True:
    yanzhengma = checkcode()
    print("验证码:",yanzhengma)
    user_in = str(input("请输入验证码:"))
    if user_in.lower() == yanzhengma.lower() :
        print("验证成功")
        break
    else :
        print("输入错误,请重新输入!")

运行结果

 

转载于:https://www.cnblogs.com/Dzc163/p/8484009.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/54618
推荐阅读
相关标签
  

闽ICP备14008679号