学生信息计划(添加到)如何添加两种方法

时间:2019-01-23 15:56:23

标签: python

我们将添加到上周完成的代码中。我们的讲师给了我们指导(在底部发布),对我和我的伴侣来说,它们不是很具描述性。我不是在寻求代码的答案,而只是要求提供一个不同且内容更多的描述或提示,以开始进行这些添加。

import math

class Student:

    def __init__(self, name, student_id, intended_major, grade):
        self.name = name
        self.student_id = student_id
        self.intended_major = intended_major
        self.grade = grade
        self._exams = []
        self._quizzes = []
        self._projects = []

    def get_name(self):
        return self.name

    def get_student_id(self):
        return self.student_id

    def get_major(self):
        return self.intended_major

    def set_quizzes(self, _quizzes):
        self._quizzes = _quizzes[:]

    def set_exams(self, _exams):
        self._exams = _exams[:]

    def set_projects(self, _projects):
        self._projects = _projects[:]

    def get_exams_mean(self):
        return float((sum(self._exams)) / max(len(self._exams), 1))

    def get_exams_median(self):
        if len(self._exams) == 0:
            return 0

        lst = sorted(self._exams)

        if len(lst) % 2 == 0:
            n1 = lst[int(len(lst)/2)]
            n2 = lst[int(len(lst)/2)-1]
            return ( n1 + n2 ) / 2
        else:
            return lst[int(len(lst) / 2)]

    def get_exams_std_dev(self):
        if len(self._exams) == 0:
            return 0

        mean = sum(self._exams) / len(self._exams)
        total = 0
        for i in self._exams:
            total += (i - mean)**2
        return math.sqrt(total/len(self._exams))

    def get_quizzes_mean(self):
        return float((sum(self._quizzes)) / max(len(self._quizzes), 1))

    def get_quizzes_median(self):
        if len(self._quizzes) == 0:
            return 0

        lst = sorted(self._quizzes)

        if len(lst) % 2 == 0:
            n1 = lst[int(len(lst) / 2)]
            n2 = lst[int(len(lst) / 2) -1]
            return ( n1 + n2 ) / 2
        else:
            return lst[int(len(lst) / 2)]

    def get_quizzes_std_dev(self):
        if len(self._quizzes) == 0:
            return 0

        mean = sum(self._quizzes) / len(self._quizzes)
        total = 0
        for i in self._quizzes:
            total += (i - mean) ** 2
        return math.sqrt(total / len(self._quizzes))

    def get_projects_mean(self):
        return float((sum(self._projects)) / max(len(self._projects), 1))

    def get_projects_median(self):
        if len(self._projects) == 0:
            return 0

        lst = sorted(self._projects)

        if len(lst) % 2 == 0:
            n1 = lst[int(len(lst)/2)]
            n2 = lst[int(len(lst)/2)-1]
            return ( n1 + n2 ) / 2
        else:
            return lst[int(len(lst) / 2)]

    def get_projects_std_dev(self):
        if len(self._projects) == 0:
            return 0

        mean = sum(self._projects)/len(self._projects)
        total = 0
        for i in self._projects:
            total += (i - mean)**2
        return math.sqrt(total/len(self._projects))

    def set_grade_calculation_type(self):
        if True:
            return 0
        else:
            pass

    def set_quiz(self, grade, number):
        pass

将以下实例方法的存根添加到Student类:

  • set_grade_calculation_type:
    该方法采用布尔值参数:True将丢失的成绩计算为零; False会跳过计算中缺少的成绩
    您将需要将此值存储在您的课程中
    如果此方法未调用

  • ,则默认为True
  • set_quiz:
    有两个参数:等级和数字,用于标识测验
    如果测验列表中的元素少于number个,则将缺少的测验添加为 无
    由于这是计算机科学,因此我们将从测验0开始。
    例如,假设学生在测验列表中有两个测验成绩0 并且1 = [90,78],我们将其称为Student.set_quiz(89,4)。我们缺少测验2 和3,因此我们的更新列表将为[90,78,None,None,89]。将来如果 我们叫Student.set_quiz(93,2),我们会得到[90,78,93,None,89]。

  • set_exam:类似于set_quiz
  • set_project:类似于set_quiz

0 个答案:

没有答案