lock"): list = [] with open("lock","r+") as f: flag = 0 for line in f: if line.strip() == "": continue line = eva l(line) #判断账号是否存在 if line["name"] == _name: line["num"] += 1 list.append(line) else: dict2 = {} dict2["name"] = _name dict2["num"] = 1 list.append(dict2) with open("lock","w") as f1: for i in list: f1.write(str(i) + '\n')
#空文件直接写入 else: list1 = [] dict1 = {} dict1["name"] = _name dict1["num"] = 1 list1.append(str(dict1)) with open("lock","w") as f2: for j in list1: f2.write(str(j) + '\n')
def main(): name = input("用户名:") res = lock(name) if res == 0: print("%s已被冻结,请联系管理员"%name) clear_lock() exit() passwd = input("密码:") res1 = login(name,passwd) if res1 == 0: print("欢迎%s登陆CBD购物中心"%name) while True: shopping.main1(name) elif res1 == 1: print("密码错误") write_lock(name) else: print("账号不存在")
res2 = lock(name) if res2 == 0: print("%s已被冻结,请联系管理员" %name) clear_lock() exit()
if __name__ == "__main__": while True: main()
|