学生管理系统登录部分

学生管理系统登录部分

这个只是登录部分的代码

def welcome():
    print("="*40)       # 居中: "{:^{}}".format("*"*i,width)
    print("{:^{}}".format("** 欢迎来到学生管理系统 **", 35))
    print("{:^{}}".format("❤ 1,登      录", 35))
    print("{:^{}}".format("❤ 2,注      册", 35))
    print("{:^{}}".format("❤ 3,退      出", 35))
    print("="*40)


while True:
    welcome()
    choice = input("请选择(1-3):")

    # 选择登录操作
    if choice == "1":
        user_num = input("请输入你的账号:")
        user_password = input("请输入你的密码:")
        # 账号列表 {"ID": user_num} "D:\千峰\日常"
        try:
            Account_list = eval(open("D:\千峰\日常\Account_list.txt", encoding="utf-8").read())
        except FileNotFoundError:
            Account_list = []

        # 密码列表 {"ID": user_num, "password": user_password}
        try:
            password_list = eval(open("D:\千峰\日常\password_list.txt", encoding="utf-8").read())
        except FileNotFoundError:
            password_list = []
        user = {"ID": user_num}
        if user in Account_list:
            # 判断密码是否正确
            for x in password_list:
                if user_num == x["ID"]:
                    if user_password == x["password"]:
                        print("登录成功!")
                        break
                    else:
                        print("密码错误登录失败!")
                        break
        else:
            print("登录失败!账号不存在!")
            continue

    # 选择注册操作
    elif choice == "2":

        # 输入要注册的账号和密码
        user_num = input("请输入你的账号:")
        user_password = input("请输入你的密码:")

        # 账号列表 {"ID": user_num} "D:\千峰\日常"
        try:
            Account_list = eval(open("D:\千峰\日常\Account_list.txt", encoding="utf-8").read())
        except FileNotFoundError:
            Account_list = []
        # 判断账号是否已经存在
        for x in Account_list:
            if user_num == x["ID"]:
                print("注册失败!该账号已经存在。")
                break
            else:
                # 若账号不存在,将账号添加到账号列表中,并将账号列表写入文件,实现数据持久化
                Account_list.append({"ID": user_num})
                open("D:\千峰\日常\Account_list.txt", "w", encoding="utf-8").write(str(Account_list))

                # 密码列表 {"ID": user_num, "password": user_password} "D:\千峰\日常"
                try:
                    password_list = eval(open("D:\千峰\日常\password_list.txt", encoding="utf-8").read())
                except FileNotFoundError:
                    password_list = []
                password_list.append({"ID": user_num, "password": user_password})
                open("D:\千峰\日常\password_list.txt", "w", encoding="utf-8").write(str(password_list))

                print("注册成功!请返回登录。")
                continue

    # 选择退出操作
    elif choice == "3":
        print("期待你下次使用管理系统 :D")
        break
    # 如果输入错误
    elif choice not in ["1", "2", "3"]:
        print("输入错误!请重新选择。")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值