编写一个学生类,学生数据有编号、姓名、年龄、专业和成绩,要求将编号、姓名、年龄数据设计成一个人类Person,并作为学生类Student的基类。创建Student类对象,并使用显示show()函数对数据进行输出。
时间: 2024-06-11 09:09:26 浏览: 63
设计一个学生类Student(学生学号、姓名、数学、英语、计算机成绩;)
5星 · 资源好评率100%
```python
class Person:
def __init__(self, id, name, age):
self.id = id
self.name = name
self.age = age
class Student(Person):
def __init__(self, id, name, age, major, grade):
super().__init__(id, name, age)
self.major = major
self.grade = grade
def show(self):
print("ID: ", self.id)
print("Name: ", self.name)
print("Age: ", self.age)
print("Major: ", self.major)
print("Grade: ", self.grade)
s = Student("001", "Tom", 18, "Computer Science", 90)
s.show()
```
输出结果:
```
ID: 001
Name: Tom
Age: 18
Major: Computer Science
Grade: 90
```
阅读全文