python输出格式: 参考输出样例输出该同学的各科成绩的最高分和总成绩,输入格式: 在一行内输入学生的姓名、年龄、语文成绩、数学成绩、英语成绩,用英文逗号分隔,定义一个Student类,包含以下私有属性: 姓名、年龄、语文成绩、数学成绩、英语成绩(其中,每个科目的成绩类型为整数)输入样例: Tom,20,78,80,82 输出样例: Tom's highest score in all subjects is 81, and his total score is 240.
时间: 2024-02-11 16:09:31 浏览: 43
好的,以下是可以用来解决这个问题的 Python 代码:
```python
class Student:
def __init__(self, name, age, chinese, math, english):
self.name = name
self.age = age
self.chinese = chinese
self.math = math
self.english = english
def highest_score(self):
return max(self.chinese, self.math, self.english)
def total_score(self):
return self.chinese + self.math + self.english
input_str = input("请输入学生的姓名、年龄、语文成绩、数学成绩、英语成绩,用英文逗号分隔:")
name, age, chinese, math, english = input_str.split(",")
student = Student(name, int(age), int(chinese), int(math), int(english))
highest_score = student.highest_score()
total_score = student.total_score()
print("{}'s highest score in all subjects is {}, and his total score is {}.".format(student.name, highest_score, total_score))
```
在运行程序时,你可以输入以下内容来测试程序:
```
Tom,20,78,80,82
```
程序会输出以下内容:
```
Tom's highest score in all subjects is 82, and his total score is 240.
```
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)