鱼C论坛

 找回密码
 立即注册
查看: 782|回复: 2

问题求助

[复制链接]
发表于 2023-10-27 21:49:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
## More background information

### More on `get_classification()`
* It takes a `list` of `list` representing the exam record of a student for three years, with each sub-list representing an attempt at a course in the form `[<course name>, <unit>, <year>, <attempt>, <mark>]`. See the section `Exam record format` for more details
* It returns the corresponding classification (type: `str`, possible values: `'First Class Honours'`, `'Upper Second Class Honours'`, `'Lower Second Class Honours'`, `'Third Class Honours'`, `'Pass'` (if penalty rule considered) and `'Fail'`) the student will get based on the given exam record

### Exam record format
The exam record is in the form of a `list` of `list`, with each sub-list representing an attempt at a course in the form `[<course name>, <unit>, <year>, <attempt>, <mark>]`. Here is an example of a record:

```
[['ST101A', 0.5, 1, 1, 92],
['MA100', 1, 1, 1, 39],
['MA100', 1, 1, 2, 54],
['EC1A3', 0.5, 1, 1, 22],
['EC1A3', 0.5, 1, 2, 34],
['EC1A3', 0.5, 1, 3, 32],
...
['MA222', 0.5, 2, 1, 30],
['MA222', 0.5, 2, 2, 38],
...
['ST310', 0.5, 3, 1, 88],
['ST311', 0.5, 3, 1, 67]]
```

Some explanation:
* `['ST101A', 0.5, 1, 1, 92]` means the student took the course 'ST101A' which is a half-unit in year 1. The record is for the first attempt with a mark of 92
* `['MA100', 1, 1, 1, 39]` means the student took the course 'MA100' which is a full-unit in year 1. The record is for the first attempt with a mark of 39
* `['MA100', 1, 1, 2, 54]` means the student took the course 'MA100' which is a full-unit in year 1. The record is for the second attempt with a mark of 54
* `['EC1A3', 0.5, 1, 3, 32]` means the student took the course 'EC1A3' which is a half-unit in year 1. The record is for the third attempt with a mark of 32
* `['MA222', 0.5, 2, 2, 38]` means the student took the course 'MA222' which is a half-unit in year 2. The record is for the second attempt with a mark of 38
* `['ST311', 0.5, 3, 1, 67]` means the student took the course 'ST311' which is a half-unit in year 3. The record is for the first attempt with mark 67

## Instructions

Describe how you will implement `get_classification()` via _decomposition_. Please also state what function(s) you will define, what they do to help you solve the original problem and implement `get_classification()`. In [src/lse_classification.py](src/lse_classification.py), implement as far as you can towards implementing `get_classification()`.

* Your answer: _________

---

## Assumptions on the function argument

* All marks are `int`, with each mark between 0 and 100
* Assume the exam record is complete, with no further re-attempt or resit is needed
* For simplicity, if "LSE100" is in the record, it bears 0.5 units
* You may ignore the penalty rule of LSE listed in part (a)

---

## Other requirements

* Use `lse_classification` as a _module_. Please do NOT copy the function definitions into `test_lse_classification.py`
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-10-27 21:50:16 | 显示全部楼层
要实现 get_classification() 函数,我们可以通过分解问题的方式来实现。

首先,我们可以定义一个函数 calculate_average_mark() ,用于计算学生在每门课程上的平均分数。这个函数将接收一个学生的考试记录作为参数,并返回一个字典,其中键是课程名称,值是平均分数。

接下来,我们可以定义一个函数 calculate_weighted_average() ,用于计算学生的加权平均分数。这个函数将接收一个学生的平均分数字典作为参数,并返回加权平均分数。

然后,我们可以定义一个函数 apply_penalty_rule() ,用于根据惩罚规则来调整学生的加权平均分数。这个函数将接收一个学生的加权平均分数作为参数,并返回调整后的加权平均分数。

最后,我们可以定义函数 get_classification() ,用于根据学生的考试记录来确定学生的分类。这个函数将接收一个学生的考试记录作为参数,并返回学生的分类。

在 get_classification() 函数中,我们可以首先调用 calculate_average_mark() 函数来计算学生在每门课程上的平均分数。然后,我们可以调用 calculate_weighted_average() 函数来计算学生的加权平均分数。最后,我们可以调用 apply_penalty_rule() 函数来根据惩罚规则调整学生的加权平均分数,并返回学生的分类。

在[lse_classification.py](src/lse_classification.py)中,我们可以实现上述函数,并尽可能地实现 get_classification() 函数。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-10-27 21:51:27 | 显示全部楼层
To implement get_classification() via decomposition, I would define the following helper functions:

1. calculate_weighted_average(): This function calculates the weighted average of marks for a given course in the exam record. It takes the course name and the exam record as inputs and returns the weighted average.

2. classify_student(): This function determines the classification for a student based on their weighted average mark. It takes the weighted average as an input and returns the corresponding classification.

3. get_classification(): This is the main function that combines the above helper functions. It takes the exam record as an input. Inside this function, we will iterate over the courses in the exam record, calculate the weighted average for each course using calculate_weighted_average(), and store the results. Finally, we will determine the overall weighted average by summing up the weighted averages of all courses and dividing it by the total number of units. We will then pass this overall weighted average to classify_student() to get the final classification, which will be returned by get_classification().

Here is an example implementation in Python:
def calculate_weighted_average(course_name, exam_record):    total_weighted_marks = 0    total_units = 0        for record in exam_record:        if record[0] == course_name:            unit = record[1]            mark = record[4]            total_weighted_marks += unit * mark            total_units += unit        if total_units > 0:        return total_weighted_marks / total_units    else:        return 0def classify_student(weighted_average):    if weighted_average >= 70:        return 'First Class Honours'    elif weighted_average >= 60:        return 'Upper Second Class Honours'    elif weighted_average >= 50:        return 'Lower Second Class Honours'    elif weighted_average >= 40:        return 'Third Class Honours'    elif weighted_average >= 35:        return 'Pass'    else:        return 'Fail'def get_classification(exam_record):    weighted_averages = []        for record in exam_record:        course_name = record[0]        weighted_average = calculate_weighted_average(course_name, exam_record)        weighted_averages.append(weighted_average)    overall_weighted_average = sum(weighted_averages) / len(weighted_averages)    classification = classify_student(overall_weighted_average)        return classification
Note that this is a simplified implementation and may need further modifications based on additional requirements or constraints.

球一个最佳答案谢谢啦!这对我非常重要!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-24 02:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表