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

      

  • 相关阅读:
    AS将一个项目导入到另一个项目中
    Android Studio出现:Cause: unable to find valid certification path to requested target
    小米手机Toast带app名称
    PopupWindow 点击外部区域无法关闭的问题
    EditText inputType类型整理
    Fragment通过接口回调向父Activity传值
    Android selector一些坑
    Installation failed with message Failed to commit install session 634765663 with command cmd package
    旷视上海研究院机器人方向招聘
    语义SLAM的数据关联和语义定位(四)多目标测量概率模型
  • 原文地址:https://www.cnblogs.com/kevin-hou1991/p/13583566.html
Copyright © 2011-2022 走看看