day13作业 —— 管理系统
def face():
print("==============================")
print(" **欢迎来到XX管理系统** ")
print()
print(" 1.登 录")
print(" 2.注 册")
print(" 3.退 出")
print()
print("==============================")
def func1():
name_old = str(input("请输入账号:"))
password_old = str(input("请输入密码:"))
old_dict = {
name_old: password_old}
f = open(".management system.txt", "r", encoding="utf-8")
record_dict = eval(f.read())
record_list = list(record_dict.keys())
if name_old in record_list:
if password_old == record_dict[name_old]:
print("欢迎进入XX管理系统!")
else:
print("密码错误!")
else:
print("该用户还未注册,请先注册!")
f.close()
def func2():
name_new = str(input("请输入账号(3-6位):"))
password_new = str(input("请输入密码(6-12位):"))
f = open(".management system.txt", "r", encoding="utf-8")
record_dict = eval(f.read())
record_list = list(record_dict.keys())
if 3<= len(name_new) <=6 and 6<= len(password_new) <=12:
if name_new in record_list:
print("注册失败!该账号已经存在!")
else:
new_dict = {
name_new: password_new}
record_dict.update(new_dict)
f = open(".management system.txt", "w", encoding="utf-8")
f.write(str(record_dict))
f.close()
print("您已注册成功!")
else:
print("请输入正确的用户名及密码!")
f.close()
def main():
while 1:
face()
num = int(input("请选择【1-3】:"))
if num == 1:
func1()
if num == 2:
func2()
if num == 3:
break
if __name__ == '__main__':
main()