#用户登录题,三次未对失败,三次登录相同用户,并出错,锁定用户。
f = open("text.txt","r") user_pass = {} for line in f: u,p = line.split(',') user_pass[u] = p.strip() f = open("lock_a.txt","r") data = f.read() count = 0 lock_a = None sign = True while count < 3: user_n = input(">:") if user_n in data: print("已被锁定。") exit() pass_w = input(">>:") if count == 0: lock_a = user_n if lock_a != user_n: sign = False if user_n in user_pass: if user_pass[user_n] == pass_w: print("欢迎登录") break else: print("抱歉,账号或者密码错误") else: print("没有这个用户") count += 1 else: print("次数太多") if sign == True: print("锁定") f = open("lock_a.txt","a") f.write("%s\n"%user_n) f.close()