pta 上的 python 代码问题
一名开发者提供了以下代码,希望实现学生成绩分析的功能:
...
测试输入如下:
jack tom jim 95 84 32 90 75 45 85 90 67
然而,代码只通过了部分测试点。问题出在哪里呢?
立即学习“Python免费学习笔记(深入)”;
分析
该代码有两个主要问题:
改进的代码
class Student: sum_score = 0 def __init__(self, s_name, m_score, c_score, e_score): self.s_name = s_name self.m_score = m_score self.c_score = c_score self.e_score = e_score def get_sum(self): for i in range(len(self.s_name)): self.sum_score += self.m_score[i] + self.c_score[i] + self.e_score[i] list_score1.append(self.sum_score) def get_best(self): list_score2 = sorted(list_score1) for k in range(len(list_score2)): if list_score2[k] == list_score1[0]: best_name = self.s_name[k] print(f'{best_name} {self.m_score[k]} {self.c_score[k]} {self.e_score[k]}', end='')
以上就是PTA Python 代码问题:学生成绩分析代码为何无法通过所有测试点?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号