1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| while True: print(''' 1.用户注册 2.用户登录 3.退出系统 ''') options = input("请输入选项>>>: ").strip() if options == '1': username = input("请输入用户名>>>: ").strip() password = input("请输入密码>>>: ").strip() msg = "%s|%s\n" % (username, password) with open(r'user.txt', 'r', encoding='utf8') as f_reg: for line in f_reg: name = line.split("|")[0] if name == username: print("用户名已存在!") break else: with open(r'user.txt', 'a', encoding='utf8') as f_reg_insert: f_reg_insert.write(msg) print("%s注册成功" % username) elif options == '2': name = input("请输入用户名>>>: ").strip() pwd = input("请输入密码>>>: ").strip() with open(r'user.txt', 'r', encoding='utf8') as f_log: for line in f_log: u_name, passwd = line.split("|") if u_name == name and passwd.strip("\n") == pwd: print("登录成功!") break else: print("登录失败,用户名或密码错误!") elif options == '3': print("退出系统!!!") break else: print("输入的选项不正确,请重新输入!")
|