1、父类(学生):姓名、学号、成绩(考勤、作业、答辩),修改成绩、查看成绩 2、人工智能的学生:专业、科目,查看父类属性(姓名、学号、成绩) 2、大数据的学生:专业、科目,查看父类属性(姓名、学号、成绩,通过特殊字符分隔开)
时间: 2023-11-08 14:47:05 浏览: 90
以下是代码实现:
```python
class Student:
def __init__(self, name, id, attend_score, homework_score, defense_score):
self.name = name
self.id = id
self.attend_score = attend_score
self.homework_score = homework_score
self.defense_score = defense_score
def modify_score(self, item, score):
if item == 'attend':
self.attend_score = score
elif item == 'homework':
self.homework_score = score
elif item == 'defense':
self.defense_score = score
else:
print('Invalid item')
def check_score(self):
print('Name: ', self.name)
print('ID: ', self.id)
print('Attend score: ', self.attend_score)
print('Homework score: ', self.homework_score)
print('Defense score: ', self.defense_score)
class AIStudent(Student):
def __init__(self, name, id, attend_score, homework_score, defense_score, major, subject):
super().__init__(name, id, attend_score, homework_score, defense_score)
self.major = major
self.subject = subject
def check_score(self):
super().check_score()
print('Major: ', self.major)
print('Subject: ', self.subject)
class BigDataStudent(Student):
def __init__(self, name, id, attend_score, homework_score, defense_score, major, subject):
super().__init__(name, id, attend_score, homework_score, defense_score)
self.major = major
self.subject = subject
def check_score(self):
super().check_score()
print('Major: ', self.major)
print('Subject: ', self.subject)
print('Score string: ', self.name + '|' + self.id + '|' + str(self.attend_score) + '|' + str(self.homework_score) + '|' + str(self.defense_score))
# 示例使用
ai_student = AIStudent('Alice', '001', 90, 80, 95, 'Artificial Intelligence', 'Deep Learning')
ai_student.check_score()
bigdata_student = BigDataStudent('Bob', '002', 85, 95, 90, 'Big Data', 'Data Mining')
bigdata_student.check_score()
```
运行结果:
```
Name: Alice
ID: 001
Attend score: 90
Homework score: 80
Defense score: 95
Major: Artificial Intelligence
Subject: Deep Learning
Name: Bob
ID: 002
Attend score: 85
Homework score: 95
Defense score: 90
Major: Big Data
Subject: Data Mining
Score string: Bob|002|85|95|90
```
阅读全文