使用字典、循环结构完成学生管理系统

文章描述了一个基于Python编写的简易学生管理系统,包括操作员登录、注册功能以及对学生信息(如姓名、年龄、性别和成绩)的录入、删除和查询操作。
摘要由CSDN通过智能技术生成

运行展示:

代码实现:

user_dict = {
    "001": {"id": "001", "password": "123456"},
    "002": {"id": "002", "password": "321321"}
}
stu_dict = {
    "001": {"id": "001", "name": "tom", "age": "18", "sex": "男", "score": "98"},
    "002": {"id": "002", "name": "jerry", "age": "19", "sex": "女", "score": "97"},
    "003": {"id": "003", "name": "joker", "age": "30", "sex": "女", "score": "60"}
}

while True:
    print("               学生管理系统")
    print("- * - * - * - * - * - * - * - * - * - * - * - * - * -")
    print("              1. 操作员登录")
    print("              2. 操作员注册")
    print("              3. 退出系统")
    print("- * - * - * - * - * - * - * - * - * - * - * - * - * -")
    a = int(input("请输入选项"))
    if a == 1:
        user_id = input("请操作员输入账号")
        user_passwd = input("请输入密码")
        for user in user_dict.values():
            if user_id == user.get("id") and user_passwd == user.get("password"):
                   # 展示登录成功界面
                print("登录成功!")
                while True:
                    print("学生管理系统-主页")
                    print("- * - * - * - * - * - * - * - * - * - * - * - * - * -")
                    print("1. 录入学员信息")
                    print("2. 删除学员信息")
                    print("3. 查询学员信息")
                    print("4. 退出系统")
                    print("- * - * - * - * - * - * - * - * - * - * - * - * - * -")
                    b = int(input("请输入选项:"))
                    if b == 1:
                        id = input("请输入学生账号:")
                        name = input("请输入学生姓名:")
                        age = input("请输入学生年龄:")
                        sex = input("请输入学生性别:")
                        score = input("请输入学生成绩:")
                        stu_dict1 = {
                            "id": id, "name": name, "age": age, "sex": sex, "score": score
                            # name, age, gender, score
                        }
                        stu_dict[id] = stu_dict1
                        input("录入完成按任意键退出!")
                        continue
                    elif b == 2:
                        stu_id = input("请输入你要删除的学员id:")
                        for stu in stu_dict.values():
                            if stu_id == stu.get('id'):
                                # 展示要删除的学员信息
                                print("----------------------------------------")
                                print("学号--|--姓名--|--年龄--|--性别--|--计算机成绩--|")
                                print(stu.get("id"), stu.get("name"), stu.get("age"),
                                      stu.get("sex"), stu.get("score"), sep="--|--")
                                print("----------------------------------------")
                                isDel = input("确定要删除该学员吗(Y/N)?")
                                if isDel.upper() == "Y":
                                    del stu_dict[stu_id]
                                    input("学员信息删除成功,按任意键返回主页")

                                else:
                                    input("用户取消了删除操作,按任意键返回主页")
                                break
                        else:
                            input("未找到该学员,请检查编号是否正确,按任意键返回上一级")

                    elif b == 3:
                        print("学号--+--姓名--+--年龄--+--性别--+--计算机成绩")
                        for stu in stu_dict.values():
                            print(stu.get("id"), stu.get("name"), stu.get("age"),stu.get("sex"), stu.get("score"),)
                        input("查询完成按任意键退出!")
                        continue
        else:
                input("密码错误,按任意键返回")

    elif a == 2:
        print("                   管理员注册")
        print("- * - * - * - * - * - * - * - * - * - * - * - * - * -")
        user_id = input("请输入您的账号")
        user_passwd = input("请输入您的密码")
        user_dict[user_id] = {"id": user_id, "password": user_passwd}
        input("注册成功,按任意键返回主页面")














评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值