[Python急救站]简单的学生管理系统

简单的学生管理系统

class Student:
    def __init__(self, name, student_id, score):
        self.name = name
        self.student_id = student_id
        self.score = score


class StudentManager:
    def __init__(self):
        self.students = []

    def add_student(self, student):
        self.students.append(student)

    def find_student(self, student_id):
        for student in self.students:
            if student.student_id == student_id:
                return student
        return None

    def update_student_score(self, student_id, new_score):
        student = self.find_student(student_id)
        if student:
            student.score = new_score
            return True
        return False


# 创建学生管理对象
manager = StudentManager()

while True:
    print("请选择功能:")
    print("1. 录入学生成绩")
    print("2. 查找学生成绩")
    print("3. 修改学生成绩")
    print("0. 退出")
    choice = input("请输入功能编号:")

    if choice == "1":
        # 录入学生成绩
        name = input("请输入学生姓名:")  # 如输入姓名:林渊达
        student_id = input("请输入学生学号:")  # 如输入学号:222190108
        score = float(input("请输入学生成绩:"))
        student = Student(name, student_id, score)
        manager.add_student(student)
        print("学生成绩录入成功")

    elif choice == "2":
        # 查找学生成绩
        student_id = input("请输入学生学号:")  # 222190108
        student = manager.find_student(student_id)
        if student:
            print("学生姓名:", student.name)  # 林渊达
            print("学生成绩:", student.score)
        else:
            print("未找到该学生")

    elif choice == "3":
        # 修改学生成绩
        student_id = input("请输入学生学号:")
        new_score = float(input("请输入新的成绩:"))
        if manager.update_student_score(student_id, new_score):
            print("成绩修改成功")
        else:
            print("未找到该学生")

    elif choice == "0":
        # 退出程序
        break

    else:
        print("无效的功能编号,请重新输入")

 

posted @ 2024-03-13 10:11  Jinylin  阅读(65)  评论(0编辑  收藏  举报