学校(School)主要有3大角色:学校(School),讲师(Teacher),学员(Student).
学校可以注册学员,统计有多少学员
讲师负责讲课
学生听课,提问,学习,交学费
Teacher # 讲师中的属性如下
name # 姓名
age # 年龄
sex # 性别
salary # 工资
course # 课程
Student # 学生中的属性如下
name # 姓名
age # 年龄
sex # 性别
salary # 工资
course # 课程
stu_id # 学生id
grade # 班级
请用Python语言简要实现这些类及及其属性,以及它们之间的关系。
请各实例两个讲师和学生实例,并打印他们的属性
class School:
pass
class SchoolPerson:
def __init__(self, name, age, sex, salary, course):
self.name = name
self.age = age
self.sex = sex
self.salary = salary
self.course = course
class Teacher(SchoolPerson):
def __init__(self, name, age, sex, salary, course):
super(Teacher, self).__init__(name, age, sex, salary, course)
class Student(SchoolPerson):
def __init__(self, name, age, sex, salary, course, stu_id, grade):
super(Student, self).__init__(name, age, sex, salary, course)
self.stu_id = stu_id
self.grade = grade
if __name__ == '__main__':
Irene = Teacher(name="Irene", age=28, sex=0, salary=4300, course=["语文", "政治", "历史"])
Andrew = Teacher(name="Andrew", age=43, sex=1, salary=7800, course=["数学", "物理", "计算机"])
Alex = Student(name="Alex", age=18, sex=1, salary=5500, course=["数学", "计算机"], stu_id=18023309, grade=3)
Vicky = Student(name="Vicky", age=18, sex=0, salary=7700, course=["数学", "物理"], stu_id=20601028, grade=1)
print(Irene.__dict__)
print(Andrew.__dict__)
print(Alex.__dict__)
print(Vicky.__dict__)
输出
{'name': 'Irene', 'age': 28, 'sex': 0, 'salary': 4300, 'course': ['语文', '政治', '历史']}
{'name': 'Andrew', 'age': 43, 'sex': 1, 'salary': 7800, 'course': ['数学', '物理', '计算机']}
{'name': 'Alex', 'age': 18, 'sex': 1, 'salary': 5500, 'course': ['数学', '计算机'], 'stu_id': 18023309, 'grade': 3}
{'name': 'Vicky', 'age': 18, 'sex': 0, 'salary': 7700, 'course': ['数学', '物理'], 'stu_id': 20601028, 'grade': 1}