zoukankan      html  css  js  c++  java
  • 继承练习

    import pickle

    class School:
    name_school='oldboy'
    def __init__(self, name, address):
    self.sch_name=name
    self.sch_address=address
    self.classes = []

    @property
    def tell_sch_info(self):
    info='学校信息:校区:%s 地址:%s' %(
    self.sch_name,
    self.sch_address
    )
    return info

    def related_class(self,schcla_obj):
    self.classes.append(schcla_obj)

    @property
    def tell_class(self):
    info=self.tell_sch_info
    for schcla_obj in self.classes:
    infos=schcla_obj.tell_scs_info
    return info,infos

    class SchoolClass:

    def __init__(self,name):
    self.schcla_name = name
    self.course=[]

    def related_course(self, cou_obj):
    self.course.append(cou_obj)

    @property
    def tell_scs_info(self):
    info='班级名称:%s' % (
    self.schcla_name,
    )
    for cou_obj in self.course:
    infos=cou_obj.tell_course_info
    return info,infos

    class Course:

    def __init__(self, name,price,cycle):
    self.cou_name=name
    self.cou_price=price
    self.cou_cycle=cycle
    self.cou_teach=[]

    def related_teach(self, tea_obj):
    self.cou_teach.append(tea_obj)

    @property
    def tell_course_info(self):
    info='课程信息:名字:%s 价格:%s 周期:%s' %(
    self.cou_name,
    self.cou_price,
    self.cou_cycle
    )
    for tea_obj in self.cou_teach:
    infos=tea_obj.tell_info
    return info,infos

    class Info:
    def __init__(self, name,age,gender):
    self.name=name
    self.age = age
    self.gender = gender

    class Teacher(Info):
    school_teach='oldboy'

    def __init__(self, name,age,gender,salary,level):
    Info.__init__(self, name,age,gender)
    self.salary=salary
    self.level=level

    @property
    def tell_info(self):
    info='教师信息:名字:%s 年龄:%s 性别:%s 薪资:%s 等级:%s' %(
    self.name,
    self.age,
    self.gender,
    self.salary,
    self.level
    )
    return info

    class Student(Info):

    def __init__(self,name,age,gender,number):
    Info.__init__(self, name, age, gender)
    self.number=number
    self.course = None

    def related_school(self, sch_obj):
    self.course=sch_obj

    @property
    def tell_stu_info(self):
    info='学生信息:名字:%s 年龄:%s 性别:%s 学号:%s' %(
    self.name,
    self.age,
    self.gender,
    self.number
    )
    infos=self.course.tell_class
    return info,infos

    stu1_obj=Student('tank',18,'male',111)
    stu2_obj=Student('lili',19,'female',222)
    stu3_obj=Student('jack',20,'male',333)

    tea_obj1=Teacher('lxx',38,'male',20000,6)

    sch_obj1=School('上海','虹桥')
    schcla_obj1=SchoolClass('python十一期')
    cou_obj1=Course('Python',20000,6)
    stu1_obj.related_school(sch_obj1)
    sch_obj1.related_class(schcla_obj1)
    schcla_obj1.related_course(cou_obj1)
    cou_obj1.related_teach(tea_obj1)
    info_student=stu1_obj.tell_stu_info
    print(info_student)

    with open('student.pickle', 'wb') as f1:
    pickle.dump(info_student, f1)

    with open('student.pickle', 'rb') as f2:
    info=pickle.load(f2)

    print(info)
  • 相关阅读:
    状态压缩dp未吃透の笔记
    洛谷blog传送门qwq
    线段树学习总结(Do not be the cheater)
    第三届NOI Online普及组线上比赛赛后总结
    第三届NOI Online入门组第三题 手表(watch)题解
    P1162 填涂颜色 题解(勿抄袭)
    4980:拯救行动 题解
    P1433 吃奶酪 题解(勿抄袭)
    Mysql-多表数据记录查询
    java-多线程
  • 原文地址:https://www.cnblogs.com/0B0S/p/12669498.html
Copyright © 2011-2022 走看看