用Python编写学生类Student,包含: 属性: 学号、姓名、班级、语文成绩、数学成绩、英语成绩;
时间: 2023-09-12 12:03:47 浏览: 163
方法:获取总分、平均分、打印学生信息。
好的,你可以这样编写这个学生类:
```python
class Student:
def __init__(self, id, name, grade, chinese_score, math_score, english_score):
self.id = id
self.name = name
self.grade = grade
self.chinese_score = chinese_score
self.math_score = math_score
self.english_score = english_score
def get_total_score(self):
return self.chinese_score + self.math_score + self.english_score
def get_average_score(self):
return self.get_total_score() / 3
def print_info(self):
print("学号:", self.id)
print("姓名:", self.name)
print("班级:", self.grade)
print("语文成绩:", self.chinese_score)
print("数学成绩:", self.math_score)
print("英语成绩:", self.english_score)
print("总分:", self.get_total_score())
print("平均分:", self.get_average_score())
```
这个学生类包含了学号、姓名、班级、语文成绩、数学成绩、英语成绩这些属性,以及获取总分、平均分和打印学生信息的方法。你可以根据你的需求调用这些方法。
阅读全文