定义Student类和Score类,输出一个学生的成绩单(包括学号、姓名、高等数学、英语成绩)。
时间: 2024-01-29 15:02:00 浏览: 85
以下是Python代码实现:
```python
class Score:
def __init__(self, math_score, english_score):
self.math_score = math_score
self.english_score = english_score
class Student:
def __init__(self, student_id, name, score):
self.student_id = student_id
self.name = name
self.score = score
def print_score(self):
print("学号:{}".format(self.student_id))
print("姓名:{}".format(self.name))
print("高等数学成绩:{}".format(self.score.math_score))
print("英语成绩:{}".format(self.score.english_score))
score = Score(90, 85) # 创建Score对象
student = Student("20190101", "张三", score) # 创建Student对象
student.print_score() # 输出学生的成绩单
```
输出结果如下:
```
学号:20190101
姓名:张三
高等数学成绩:90
英语成绩:85
```