Python write simple user login system
topic:
1. There are multiple users in the system, and the user's information is currently stored in the list.
users=['root','westos']
passward=['123','456']
2. User login (determine whether the user login is successful
- Determine whether the user exists
- if it exists
(1). Judge whether the user password is correct
如果正确,登陆成功,退出循环
如果密码不正确,重新登录,一共有三次机会登录
-
If the user does not exist
重新登录,一共有三次机会登录
The demo code is as follows:
users=['root','westos']
passward=['123','456']
n=0
while n<3:
user=input('users:')
n+=1
if(user in users):
index=users.index(user) #用index方法取出输入users的位置
passw=input('passward:')
passw1=passward[index] #将index值返回在passward中
if(passw==passw1):
print("login success")
break
else:
print("passward wrong,please relogin")
else:
print("users wrong,please relogin")
else:
print("Three login opportunities are exhausted")
operation result: