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>]
    

      

  • 相关阅读:
    vmware和主机通信方法
    曾经的读书计划
    Linux下的autoconf和automake
    Nor Flash读写方法
    Linux下的动态库和静态库
    asp.net读取Xml文件到DataSet,以及DataSet保存为Xml,利用自带的强大功能
    SqlServer 2000/2005 列转行 行转列收集
    GridView 模板列 在后台获取该行某控件的值 例如批量修改
    C# DllImport的用法 调用Window的一些常用功能
    C#通用数据库操作类 支持Access/MSSql/Orale/MySql等数据库
  • 原文地址:https://www.cnblogs.com/kevin-hou1991/p/13583566.html
Copyright © 2011-2022 走看看