标签:判断 成员 显示 else 赋值 逻辑运算 lin max password
1 import sys 2 3 locking = (‘login/locking.txt‘) 4 login = (‘login/login.txt‘) 5 6 def main(): 7 count_min = 0 8 count_max = 3 9 10 while count_min < count_max: 11 username = input("请输入用户名:") # 引导用户输入用户名 12 with open(locking, ‘r‘) as locking_file: # 打开记载锁定用户的文件 13 for line in locking_file.readlines(): 14 if username == line.strip(‘\n‘): # 判断用户是否在锁定的用户文件里 15 sys.exit(‘%s用户已经被锁定。。。‘ % username) 16 17 password = input("请输入用户密码:") # 引导用户输入密码 18 with open(login, ‘r‘) as login_file: 19 for line in login_file.readlines(): 20 user,passwd = line.strip(‘\n‘).split() # 对记载用户名和密码的文件进行格式化并且分别赋值给user和passwd 21 flog = False # 定义一个变量 22 if username == user and password == passwd: # 判断用户名密码是否正确 23 print("登陆成功!") 24 flog = True # 对赋值的变量进行修改已保证退出程序 25 break 26 if flog == False: 27 if count_min < 2: 28 print("用户名密码错误,请重新输入!") 29 else: 30 lock(username) # 输入错误三次则把用户加入锁定文件 31 count_min += 1 32 else: 33 break 34 35 def lock(username): 36 with open(locking, ‘a‘) as locking_file: 37 locking_file.write(username) 38 locking_file.write(‘\n‘) 39 40 if __name__ == ‘__main__‘: 41 main()
标签:判断 成员 显示 else 赋值 逻辑运算 lin max password
原文地址:http://www.cnblogs.com/kevinMaR/p/6218957.html