用户登录

 1 #!/usr/bin/env python
 2 #-*- coding:utf-8 -*-
 3 # @Time    : 2017/9/13 10:38
 4 # @Author  : lichuan
 5 # @File    : login.py
 6 
 7 
 8 users = {
 9     'chuan' : ['123456',0],
10     'tianshuai' : ['123456',0],
11     'zhiqiang' : ['123456',0],
12 }
13 
14 count=0
15 FLAG_TAG=True
16 while FLAG_TAG:
17 
18         username = input("输入你的用户名:").strip()
19         passwd = input("输入你的密码:").strip()
20 
21         if username in users and users[username][1] < 3:
22             if users[username][0] == passwd:
23                 print("you have login successful!")
24                 FLAG_TAG = False
25             else:
26                 print("passwd is wrong!")
27                 users[username][1]+=1
28         elif username in users and users[username][1] >= 3:
29             print("user is locked!")
30             FLAG_TAG = False
31         else:
32             print("username is not exists or passwd is wrong,please input agin!")
33         count+=1
34 
35         # 尝试三次之后对用户进行提醒,并进行选择,q退出,g继续尝试
36         while count>=3:
37             print("you have input 3 times")
38             q=input("input 'q' to exit or 'g' to continue").strip()
39             if q == "q":
40                 FLAG_TAG=False
41                 break
42             elif q == 'g':
43                 count = 0
44                 continue
45             else:
46                 print("wrong input!")
47                 continue
原文地址:https://www.cnblogs.com/litzhiai/p/7515210.html