Python中运用random函数模拟用户登录验证码

来源:互联网 发布:java web完整项目 编辑:程序博客网 时间:2024/05/19 21:01
'''Created on 2017年9月8日@author: Len'''import randomUser_name,User_Pwd="Len","Len123"check=''def checking():    global check    for i in range(4):        cnumber=random.randint(0,4)        if cnumber == i:            x = chr(random.randint(65,90))                    else:            x = random.randint(0,9)        check += str(x)            return checkdef login():    username = input("请输入用户名:")    userpwd = input("请输入密码:")        while True:        if username == User_name and userpwd == User_Pwd :            print("用户名密码正确!")            checking()            print("验证码为:",check)            user_check=input("请输入验证码:")                        if user_check==check:                print ("登陆成功!")                return            else:                print("输入错误!")        else:            print("输入错误,请重新输入!")             login()             

原创粉丝点击