python练习---登录验证(三次登录)

功能要求:

1、用户登录
2、三次登录失败,如果输入Y/y就再给三次机会,不输入则退出程序
3、支持多用户登录
4、登录成功后退出程序
5、输入用户名或者密码时,随时输入q/Q可以退出程序
 1 a = 0
 2 count = 3
 3 name_list = [
 4     {'username':'张三','password':'123'},
 5     {'username':'李四','password':'456'},
 6     {'username':'王二','password':'789'},
 7 
 8 ]
 9 while True:
10     a += 1
11     if a <= 3:
12         user_name = input("Please enter your username:").strip()
13         if user_name == "q": break
14         user_password = input("Please enter your password:").strip()
15         if user_password == "q":break
16         while True:
17             for i in name_list:
18                 if user_name == i["username"] and user_password == i["password"]:
19                     print("login successfully")
20                     exit()
21             count -= 1
22             print(count)
23             break
24     elif a > 3:
25         Y = input("Please enter your y/Y:").strip()
26         if Y == "y" or Y == "Y":
27             a = 0
28         else:
29             print("不要脸")
30             break

 

posted @ 2018-04-24 21:28  飞奔的小水牛  阅读(356)  评论(0编辑  收藏  举报