继承,学校,实例,重要

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值