定义一个学生类,该类包含了,学生的学号、姓名、平时、期中、期末5个私有变量,总评为公有方法,并定义构造函数。主程序中实例化(“张三”,“1001”,86,95,90),计算平均成绩。
时间: 2023-06-02 20:06:58 浏览: 103
好的,我会按照您的要求回答问题。以下是代码实现:
```python
class Student:
def __init__(self, name, id, usual_grade, midterm_grade, final_grade):
self.__name = name
self.__id = id
self.__usual_grade = usual_grade
self.__midterm_grade = midterm_grade
self.__final_grade = final_grade
def calculate_total_grade(self):
total_grade = self.__usual_grade + self.__midterm_grade + self.__final_grade
return total_grade
def calculate_average_grade(self):
total_grade = self.calculate_total_grade()
average_grade = total_grade / 3
return average_grade
student = Student("张三", "1001", 86, 95, 90)
average_grade = student.calculate_average_grade()
print("张三的平均成绩是:", average_grade)
```
输出结果为:
```
张三的平均成绩是: 90.33333333333333
```
阅读全文