您的位置:首页 > 编程语言 > Python开发

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

2017-09-08 12:43 417 查看
'''
Created on 2017年9月8日

@author: Len
'''
import random
User_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 check

def 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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: