Jupyter Notebook定义一个student类,包括学号,姓名,性别,语文,数学,英语,计算机等属性和计算总分和平均分的两个方法。实例化对象,输出学生姓名和总分及平均分
时间: 2024-05-15 17:12:23 浏览: 40
下面是一个示例代码:
```python
class Student:
def __init__(self, id, name, gender, chinese, math, english, computer):
self.id = id
self.name = name
self.gender = gender
self.chinese = chinese
self.math = math
self.english = english
self.computer = computer
def total_score(self):
return self.chinese + self.math + self.english + self.computer
def avg_score(self):
return self.total_score() / 4
student = Student('001', '张三', '男', 80, 90, 85, 95)
print('学生姓名:{},总分:{},平均分:{}'.format(student.name, student.total_score(), student.avg_score()))
```
输出结果:
```
学生姓名:张三,总分:350,平均分:87.5
```
阅读全文