#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/5/6 0006 12:22
# @Author : Anthony.Waa
# @Site :
# @File : 用户登录(三次错误机会).py
# @Software: PyCharm
# demo1
# 定义用户列表
user_list = [
{'username': 'anthony', 'password': '123'},
{'username': 'chris', 'password': '123'},
{'username': 'alex', 'password': '123'},
{'username': 'oldboy', 'password': '123'},
]
# 定义次数
count = 0
while True:
# 用户名和密码
users = input("请输入你的用户名:")
pasws = input("请输入你的密码:")
# 循环用户列表
for lists in user_list:
if lists['username'] == users and lists['password'] == pasws:
print("登录成功")
exit()
else:
print("登录失败,请重新登陆.")
count += 1
break
if count == 3:
print("你的用户名或密码,错误输入超过3次,退出登陆")
exit()
# ======================================================================================
# demo2
# 定义用户列表
user_list = [
{'username': 'anthony', 'password': '123'},
{'username': 'chris', 'password': '123'},
{'username': 'alex', 'password': '123'},
{'username': 'oldboy', 'password': '123'},
]
# 定义次数
count = 0
# 定义状态
flag = False
while True:
# 用户名和密码
users = input("请输入你的用户名:")
pasws = input("请输入你的密码:")
# 循环用户列表
for lists in user_list:
if lists['username'] == users and lists['password'] == pasws:
flag = True
else:
pass
# 判断登陆状态
if flag:
print("登录成功")
exit()
else:
print("登录失败,请重新登陆.")
count += 1
flag = False
# 判断是否失败次数超过3次
if count == 3:
print("你的用户名或密码,错误输入超过3次,退出登陆")
exit()
用户登录(三次错误机会)
猜你喜欢
转载自www.cnblogs.com/ipyanthony/p/8998027.html
今日推荐
周排行