```python import random def cheng_ji(): """ 此函数为生成每位同学的四次成绩 """ student_scores = [] for i in range(1, 46): # 从第 1 位到第 45 位同学 midterm_score = random.randint(80, 98) # 生成期中考试成绩 final_score = random.randint(40, 100) # 生成期末考试成绩 daily_score = random.randint(85, 97) # 生成平时成绩 homework_score = random.randint(88, 100) # 生成作业成绩 student_scores.append([midterm_score, final_score, daily_score, homework_score]) # 将每位同学的成绩添加到列表中 return student_scores # 返回所有同学的成绩列表 def zong_ping(): """ 此函数为计算每位同学的总评成绩 """ student_scores = cheng_ji() # 调用生成成绩的函数获取成绩 total_evaluations = [] for score in student_scores: # 遍历每位同学的成绩 midterm = score[0] # 期中考试成绩 final = score[1] # 期末考试成绩 daily = score[2] # 平时成绩 homework = score[3] # 作业成绩 total = round(midterm * 0.3 + final * 0.4 + daily * 0.1 + homework * 0.2) # 计算总评成绩并取整 total_evaluations.append(total) # 将总评成绩添加到列表中 return total_evaluations # 返回总评成绩列表 def san_fen(): """ 此函数为计算总评成绩的最低分、最高分和平均分 """ total_evaluations = zong_ping() # 调用总评成绩计算函数获取总评成绩 min_score = min(total_evaluations) # 计算最低分 max_score = max(total_evaluations) # 计算最高分 avg_score = round(sum(total_evaluations) / len(total_evaluations)) # 计算平均分并取整 min_index = total_evaluations.index(min_score) + 1 # 获取最低分同学的索引加 1 max_index = total_evaluations.index(max_score) + 1 # 获取最高分同学的索引加 1 return (f'第{min_index}位学生', min_score, f'第{max_index}位学生', max_score, avg_score) # 返回最低分、最高分同学和平均分 1. 在生成成绩时,要确保每次生成的成绩都在指定的区间内。 2. 在计算总评成绩时,注意成绩的权重比例。 3. 在计算平均分和查找最低分、最高分的索引时,要注意索引从 0 开始,返回时需加 1 以对应学生的序号。 ``` [2024-12-22 10:14:17 | AI写代码神器 | 688点数解答]