文件操作完成登陆注册系统
- 创建需要使用的文件
-
ID.txt
================================== ❀❀ 欢迎来到xxx管理系统 ❀❀ ❤ 1. 登 录 ❤ 2. 注 册 ❤ 3. 退 出 ==================================
-
ID2.txt
[]
-
登陆注册系统代码
# 输出提示界面 f1 = open('files/ID.txt', 'r', encoding='utf-8') login_system = f1.read() print(login_system) f1.close() # 输入选项 num = int(input('请选择(1~3):')) # 打开系统文件 f2 = open('files/ID2.txt', 'rt', encoding='utf-8') id2 = eval(f2.read()) # type: list f2. close() # 登陆/注册 if num == 2: ID = input('请输入账号:') password = input('请输入密码:') user = (ID, password) if user not in id2: f3 = open('files/ID2.txt', 'wt', encoding='utf-8') id2.append(user) f3.write(str(id2)) f3.close() print('注册成功!') else: print('注册失败! 该账号已经注册过') elif num == 1: ID = input('请输入账号:') password = input('请输入密码:') user = (ID, password) for i in range(len(id2)): if user == id2[i]: print('登陆成功!') else: print('登陆失败!') else: print('')