1.启动程序,输入用户名及密码(三次输入机会)
2.判断用户名是否存在
3.判断账户是否被锁定
4.判断用户名密码是否正确
5.登录成功
代码实现如下:
user_list = [
(‘Kira‘,‘123‘),
(‘Bob‘,‘456‘),
(‘Amy‘,‘789‘),
(‘Bettie‘,‘123‘)
]
lock_user_list = [‘Bettie‘]
count = 1
while count<=3:
username = input("Please input your name:")
password = input("Please input your password:")
for index,user in enumerate(user_list):#循环储存账户的列表
#print(index,user)
userName = user_list[index][0]#获取用户名
passWord = user_list[index][1]#获取密码
if userName == username: #判断用户名是否存在于user_list
for index2,user in enumerate(lock_user_list): #循环锁定账户列表
lock_user = lock_user_list[index2]#获取被锁定用户名
#print(lock_user,username)
if lock_user != username:#判断用户是否被锁定
if username == userName and password == passWord:#判断是否达成登录成功的条件
print("Welcome %s !"%(username))
exit()
elif count==3 and (username !=userName or password != passWord):#判断是否达成被锁定的条件
lock_user_list.append(username)
print(lock_user_list)
print("Sorry,You have tried too many times!")
exit()
else :
print("Sorry,your account had be locked")
exit()
print("Please try again!")
count +=1