```python import random def cheng_ji(): """ 此函数为生成每位同学的四次成绩 """ students_scores = [] for i in range(1, 46): mid_term = random.randint(80, 98) # 生成期中考试成绩 final_term = random.randint(40, 100) # 生成期末考试成绩 daily = random.randint(85, 97) # 生成平时成绩 homework = random.randint(88, 100) # 生成作业成绩 students_scores.append([mid_term, final_term, daily, homework]) return students_scores # 返回所有学生的成绩 def zong_ping(): """ 此函数为计算每位同学的总评成绩 """ students_scores = cheng_ji() # 获取每位同学的四次成绩 total_evaluations = [] for score in students_scores: mid_term, final_term, daily, homework = score total_evaluation = round(mid_term * 0.3 + final_term * 0.4 + daily * 0.1 + homework * 0.2) # 计算总评成绩并取整 total_evaluations.append(total_evaluation) return total_evaluations # 返回所有同学的总评成绩 def san_fen(): """ 此函数为计算总评成绩的最低分、最高分和平均分 """ total_evaluations = zong_ping() # 获取所有同学的总评成绩 min_score = min(total_evaluations) # 最低分 max_score = max(total_evaluations) # 最高分 average_score = round(sum(total_evaluations) / len(total_evaluations)) # 平均分 min_index = total_evaluations.index(min_score) + 1 # 最低分学生的序号 max_index = total_evaluations.index(max_score) + 1 # 最高分学生的序号 return (f'第{min_index}位学生', min_score, f'第{max_index}位学生', max_score, average_score) # 返回最低分、最高分和平均分 # 1. 生成成绩时,要确保随机数在指定区间内,并且符合实际情况。 # 2. 计算总评成绩时,注意权重的分配要准确,计算过程不能出错。 # 3. 统计最低分、最高分和平均分的时候,要确保数据的完整性和准确性。 ``` [2024-12-21 11:55:01 | AI写代码神器 | 579点数解答]