python3.4编写程序完成以下要求:定义一个Student类,包含以下私有属性: 姓名、年龄、语文成绩、数学成绩、英语成绩(其中,每个科目的成绩类型为整数),且包含以下方法的定义: (1)获取学生的姓名:get_name() (2)获取学生的年龄:get_age() (3)返回3门科目中最高的分数:get_maxScore() (4)返回3门科目的总成绩:get_totalScore() 完成类的定义以后,在主程序中接收键盘输入的学生信息,并使用该信息创建1个学生对象,计算输出该同学各科目成绩的最高分和总成绩。 输入格式: 在一行内输入学生的姓名、年龄、语文成绩、数学成绩、英语成绩,用英文逗号分隔 输出格式: 参考输出样例输出该同学的各科成绩的最高分和总成绩 输入样例: Tom,20,78,80,82 输出样例: Tom's highest score in all subjects is 81, and his total score is 240.
时间: 2024-03-03 07:50:26 浏览: 155
代码实现如下:
```python
class Student:
def __init__(self, name, age, chinese_score, math_score, english_score):
self.__name = name
self.__age = age
self.__chinese_score = chinese_score
self.__math_score = math_score
self.__english_score = english_score
def get_name(self):
return self.__name
def get_age(self):
return self.__age
def get_maxScore(self):
return max(self.__chinese_score, self.__math_score, self.__english_score)
def get_totalScore(self):
return self.__chinese_score + self.__math_score + self.__english_score
input_str = input('请输入学生的姓名、年龄、语文成绩、数学成绩、英语成绩,用英文逗号分隔:')
input_list = input_str.split(',')
name = input_list[0]
age = int(input_list[1])
chinese_score = int(input_list[2])
math_score = int(input_list[3])
english_score = int(input_list[4])
student = Student(name, age, chinese_score, math_score, english_score)
print("{}'s highest score in all subjects is {}, and his total score is {}.".format(student.get_name(), student.get_maxScore(), student.get_totalScore()))
```
运行结果:
```
请输入学生的姓名、年龄、语文成绩、数学成绩、英语成绩,用英文逗号分隔:Tom,20,78,80,82
Tom's highest score in all subjects is 82, and his total score is 240.
```
阅读全文