酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

Python代码:轻松求解6人英语考试成绩多项指标并排序

以下是解决这个问题的Python代码: ```python # 输入6个分数 scores = [] for i in range(6): score = int(input()) scores.append(score) # 最高分及序号 max_score = max(scores) max_index = scores.index(max_score) + 1 # 最低分及序号 min_score = min(scores) min_index = scores.index(min_score) + 1 # 平均分 average = sum(scores) / len(scores) # 60分的人数 count_60 = scores.count(60) # 按由高到低排序 sorted_scores = sorted(scores, reverse=True) # 输出结果 print(f"{max_score},{max_index}") print(f"{min_score},{min_index}") print(f"{average:.1f}") print(count_60) print(','.join(map(str, sorted_scores))) ``` 代码说明: 1. 创建一个空列表`scores`,通过循环读取6个输入的成绩并存入列表。 2. 使用`max()`和`min()`函数找出最高分和最低分,`index()`方法找到它们的索引(注意加1以符合题目要求的序号)。 3. 计算平均分,保留一位小数。 4. 使用`count()`方法统计60分的人数。 5. 使用`sorted()`函数对分数进行降序排序。 6. 按要求格式输出所有结果。 这个解决方案完全符合题目要求,使用列表操作完成所有计算和排序任务。 ######[AI问答 | 317点数解答 | 2025-04-15 08:18:54]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]