class School(object):
def __init__(self,name,address):#创建类后初始化,self的出现就把后边的name和address包含在肚子里,所以在这个程序中只要被使用就包含name和address功能
self.name = name
self.address = address
self.teacher = []
self.student = []
def enroll(self,stu_obj): #出现self则说明后边的stu_obj就可以直接使用stu_obj.name
self.student.append(stu_obj)
print("%s 注册学籍" %stu_obj.name)
def hire(self,tea_obj): #出现self则说明后边的stu_obj就可以直接使用tea_obj.name 还有就是tea_obj是在self肚子中已有功能的添加
self.teacher.append(tea_obj)
print("%s 被雇佣" % tea_obj.name)
class Schoolmates(object):
def __init__(self,name,age,sex):
self.name = name
self.age = age
self.sex = sex
class Teacher(Schoolmates):
def __init__(self,name,age,sex,gongzi,kecheng):
Schoolmates.__init__(self,name,age,sex)
self.gongzi = gongzi
self.kecheng = kecheng
def teach(self):
print("%s is teaching %s" %(self.name,self.kecheng))
def tell(self):
print('''----- info teacher %s -----
name = %s
age = %s
sex = %s
gongzi = %s
kecheng = %s''' %(self.name,self.name,self.age,self.sex,self.gongzi,self.kecheng))
class Student(Schoolmates):
def __init__(self,name,age,sex,tuition,grade):
Schoolmates.__init__(self,name,age,sex)
self.tuition = tuition
self.grade = grade
def pay_tuition(self,amount):
print("%s has paid %s" %(self.name,amount))
def tell(self):
print('''----- info student %s -----
name = %s
age = %s
sex = %s
tuition = %s
grade = %s''' %(self.name,self.name,self.age,self.sex,self.tuition,self.grade))
school= School("zjut","hangzhou")
t1 = Teacher("老郭",40,"男",4000,"math")
s1 = Student("小明",21,"男",5000,5)
t1.tell()
s1.tell()
school.enroll(s1)
school.hire(t1)