zoukankan      html  css  js  c++  java
  • 4.9作业

    # 作业二:在昨天作业的基础之上
    # # 1、引入属性访问控制+property
    # # 2、引入继承与派生的概念来减少代码冗余
    # 注意:要满足什么"是"什么的关系,不满足"是"的关系不要去继承




    import pickle
    import uuid


    class Parent:
    def __init__(self,name):
    self.name=name
    self.uid=uuid.uuid4()
    self.lis=[]

    @property
    def save(self):
    with open(f'{self.uid}.pkl','wb')as f:
    return pickle.dump(self,f)


    @property
    def get(self):
    with open (f'{self.uid}.pkl','rb')as f:
    res=pickle.load(f)
    print(res.__init__)

    def related(self, id):
    self.lis.append(id)


    class School(Parent):
    school_name='oldboy'
    def __init__(self,name,addr):
    Parent.__init__(self,name)
    self.addr=addr

    @property
    def tell_school_info(self):
    print(self.name.center(60,'='))
    for id in self.lis:
    with open (f'{id}.pkl','rb')as f:
    res=pickle.load(f)
    res.tell_class_info






    class Class(Parent):
    def __init__(self,name):
    Parent.__init__(self,name)

    @property
    def tell_class_info(self):
    print('%s ' % self.name,end=' ')
    for id in self.lis:
    with open(f'{id}.pkl', 'rb',) as f:
    res=pickle.load(f)
    res.tell_course_info







    class Course(Parent):
    def __init__(self,name,period,price):
    Parent.__init__(self,name)
    self.period=period
    self.price=price

    @property
    def tell_course_info(self):
    print('<课程名:%s 周期:%s 价钱:%s>' %(self.name,self.period,self.price))


    class People:
    def __init__(self,name,age,sex):
    self.name = name
    self.age = age
    self.sex = sex
    self.uid = str(uuid.uuid4())



    class Student(People,Parent):
    def __init__(self,name,age,sex,id,):
    People.__init__(self,name,age,sex)
    self.id=id
    self.score = 0
    self.course_uid=None
    def choice(self,course_uid):
    self.course_uid=course_uid

    def tell_info(self):
    print(f'姓名:{self.name} 年龄:{self.age} 性别:{self.sex} 学号:{self.id}',end=" ")


    class Teacher(People,Parent):
    def __init__(self,name, age, sex,salary, level):
    People.__init__(self,name,age,sex)
    self.salary=salary
    self.level=level
    def score(self,student_obj,grade):
    student_obj.score=grade

    def tell_teacher(self):
    print('姓名:%s 年龄:%s 薪资:%s 等级:%s ' % (self.name, self.age,
    self.salary, self.level), end='')



    school_obj1=School('老男孩魔都校区','上海')
    class_obj1 = Class('脱产14期')
    course_obj1=Course('python全栈开发','6mons',20000)




    school_obj1.related(class_obj1.uid)
    class_obj1.related(course_obj1.uid)


    print(school_obj1)
    school_obj1.save
    class_obj1.save
    course_obj1.save


    school_obj1.tell_school_info
    school_obj1.get
    class_obj1.get
    course_obj1.get

    student_obj1=Student('cyp',18,'male',1111)
    teacher_obj1=Teacher('egon',18,'male',25000,'特级')
    student_obj1.related(class_obj1.uid)
    student_obj1.choice(course_obj1.uid)

    teacher_obj1.score(90,student_obj1)
    student_obj1.save
    teacher_obj1.save
    student_obj1.tell_info()
  • 相关阅读:
    linux环境变量(一)
    linux常用命令-ps
    linux实用小命令--查看文本内容
    postman tests常用方法
    Vue 中嵌套 Iframe,用postMessage通信 踩坑记
    [Vue warn]: Error in nextTick: "RangeError: Maximum call stack size exceeded"
    对STM32所用位带操作宏的详细剖析
    移植Modbus TCP二
    移植Modbus TCP一
    STM32位带操作
  • 原文地址:https://www.cnblogs.com/chenyoupan/p/12670452.html
Copyright © 2011-2022 走看看