zoukankan      html  css  js  c++  java
  • Succeed_School

    # Author kevin_hou
    class School(object):
        def __init__(self,name,addr):
            self.name = name
            self.addr = addr
            self.students = []
            self.staffs = []
        def enroll(self,stu_obj):
            self.students.append(stu_obj)
            print("---------Prepare for student %s enrolling--------"%stu_obj.name)
        def hire(self,staff_obj):
            self.staffs.append(staff_obj)
            print("---------hire a new staff %s--------"%staff_obj.name)
    
    class SchoolMember(object):
        def __init__(self,name,age,sex):
            self.name = name
            self.age = age
            self.sex = sex
        def tell(self):
            pass
    
    class Teacher(SchoolMember):
        def __init__(self,name,age,sex,salary,course):
            super(Teacher, self).__init__(name,age,sex)
            self.salary = salary
            self.course = course
        def tell(self):
            print(
                '''
                ----------------info of Teachers: %s-------------------
                Name: %s
                Age: %s
                Sex: %s
                Salary: %s
                Course: %s
                '''%(self.name,self.name,self.age,self.sex,self.salary,self.course))
        def tech(self):
            print("%s is teasching course [%s]"%(self.name,self.course))
    
    class Student(SchoolMember):
        def __init__(self,name,age,sex,stu_id,grade):
            super(Student, self).__init__(name,age,sex)
            self.stu_id = stu_id
            self.grade = grade
        def tell(self):
            print(
                '''
                ----------------info of Students: %s-------------------
                Name: %s
                Age: %s
                Sex: %s
                Stu_id: %s
                Grade: %s
                ''' % (self.name,self.name, self.age, self.sex, self.stu_id, self.grade))
        def pay_tution(self,amount):
            print("%s has paid tution for $s"%(self.name,amount))
    school = School("Kevin","Shanghai")
    t1 = Teacher("Alex", 22, "M", 1002,"python3")
    t2 = Teacher("Jane", 33,"F",800,"C language")
    
    s1 = Student("Curry", 22, "M", 1002,"python3")
    s2 = Student("Rossal", 33,"M",800,"C language")
    
    t1.tell()
    # ----------------info
    # of
    # Teachers: Alex - ------------------
    # Name: Alex
    # Age: 22
    # Sex: M
    # Salary: 1002
    # Course: python3
    s1.tell()
    # ----------------info
    # of
    # Students: Curry - ------------------
    # Name: Curry
    # Age: 22
    # Sex: M
    # Stu_id: 1002
    # Grade: python3
    school.hire(s1) #---------hire a new staff Curry--------
    school.enroll(s1)   #---------Prepare for student Curry enrolling--------
    school.enroll(s2)   #---------Prepare for student Rossal enrolling--------
    
    print(school.students)  #[<__main__.Student object at 0x0144CC70>, <__main__.Student object at 0x0144CCB0>]
    print(school.staffs)    #[<__main__.Student object at 0x0144CC70>]
    

      

  • 相关阅读:
    数据结构与算法习题总结——树结构
    SQL入门题集及学习笔记
    nlp入门系列笔记——阿里天池新闻文本新手赛
    linux一步一脚印--- ls -l 命令执行显示结果的每一列含义
    Python tuple元组---学习总结
    Python——列表深浅拷贝
    Python list列表---学习总结
    linux一步一脚印---mv命令
    linux一步一脚印---rm命令
    linux一步一脚印---cp命令
  • 原文地址:https://www.cnblogs.com/kevin-hou1991/p/13583566.html
Copyright © 2011-2022 走看看