class School(object):
def __init__(self,name,address):
self.name=name
self.address=address
self.student_list=[]
self.teacher_list=[]
def enroll(self,obj):
print('为学生%s注册学籍'%obj.name)
self.student_list.append(obj)
def enployed(self,obj):
print('录用%s为我校老师'%obj.name)
self.teacher_list.append(obj)
class SchoolMember(object):
def __init__(self,name,age):
self.name = name
self.age = age
class Student(SchoolMember):
def __init__(self,name,age,sex,number):
self.name=name
self.age=age
self.sex=sex
self.number=number
def pay(self,obj):
print('student %s paid xuefei'%self.name,obj)
def stu_information(self):
print('''
------student %s of information------
name=%s
age=%s
sex=%s
number=%s
'''%(self.name,self.name,self.age,self.sex,self.number))
class Teacher(SchoolMember):
def __init__(self,name,age,wage,subjects):
super().__init__(name, age)
self.name=name
self.age=age
self.wage=wage
self.subjects=subjects
def a_class(self):
print('teacher %s is teach %s'%(self.name,self.subjects))
def teach_information(self):
print('''
------teacher %s of information------
name=%s
age=%s
wage=%s
subjects=%s
'''%(self.name,self.name,self.age,self.wage,self.subjects))
school=School('hongqizhongxue','fuyang')
s1=Student('akl','21','woman','1504')
s2=Student('nuoke','183','man','001')
t1=Teacher('jianji','18','8888','shuxue')
t2=Teacher('ali','28','3000','meishu')
s1.stu_information()
t1.teach_information()
school.enroll(s1)
school.enroll(s2)
school.enployed(t1)
school.enployed(t2)
print(school.student_list)
print(school.teacher_list)
school.teacher_list[0].a_class() #教课
for a in school.student_list: #交学费
a.pay(5000)
继承,学校,实例,重要
最新推荐文章于 2024-06-13 20:19:32 发布