From 8cee6e29e5d2764ff459460ce1361118764f2f14 Mon Sep 17 00:00:00 2001 From: nwnu202331904132 <3291295349@qq.com> Date: Thu, 27 Jun 2024 18:35:46 +0800 Subject: [PATCH] ADD file via upload --- Python学生管理系统.py | 108 ++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Python学生管理系统.py diff --git a/Python学生管理系统.py b/Python学生管理系统.py new file mode 100644 index 0000000..e145e8c --- /dev/null +++ b/Python学生管理系统.py @@ -0,0 +1,108 @@ +class_info = [] + +def print_menu(): + print("-------------------") + print("学生管理系统 V1.0") + print(" 1:添加学生") + print(" 2:删除学生") + print(" 3:修改学生") + print(" 4:查询学生") + print(" 5:显示所有学生") + print(" 6:退出系统") + print("-------------------") + + +def add_student(): + print("欢迎使用添加学生的功能") + global class_info + name = input("输入学生的姓名:") + age = input("输入学生的年龄:") + score = input("输入学生的分数:") + # [{},{}] + for info in class_info: + if info["name"] == name: + print("学生姓名重名了") + return + + student = { + "name": name, + "age": age, + "score": score + } + + class_info.append(student) + print("添加学生信息成功") + print(class_info) + + +def del_student(): + print("欢迎使用删除学生的功能") + global class_info + name = input("请输入删除的学生姓名:") + for student in class_info: + if student["name"] == name: + class_info.remove(student) + print("删除学生信息成功") + return + print("您输入的学生姓名不存在") + + +def modify_student(): + global class_info + name = input("请输入需要修改的学生信息:") + for student in class_info: + if student["name"] == name: + student["name"] = input("请输入修改后的学生姓名:") + # jx = input("是否继续修改:") + # if jx == "y" or jx == "yes": + student["age"] = input("请输入修改后的学生年龄:") + student["score"] = input("请输入修改后的学生分数:") + print("修改学生信息成功") + return + print("您输入的学生信息不存在") + + +def search_student(): + global class_info + name = input("请输入要查找的学生姓名:") + for student in class_info: + if student["name"] == name: + print("姓名:%s, 年龄:%s, 分数:%s" %(student["name"], student["age"], student["score"])) + return + print("您输入的学生信息不存在") + + +def show_student(): + print("姓名--年龄---成绩") + for student in class_info: + print(student["name"], student["age"], student["score"]) + + +def main(): + """实现主要的业务逻辑""" + while True: + # print_menu() + print_menu() + choose = int(input("请输入您需要的功能:")) + + if choose == 1: + add_student() + elif choose == 2: + del_student() + elif choose == 3: + modify_student() + elif choose == 4: + search_student() + elif choose == 5: + show_student() + elif choose == 6: + print("退出系统 Bye") + break + + +if __name__ == '__main__': + main() + + + +