Work April 8

1, the object-oriented code for the job class practice explain tomorrow dictation
2, class-based object-oriented code to explain the operation, expanded write Student class
3, the sequence of addition of the deserialization operation
4, the association between the objects using the id number
5, can be found in the corresponding file by id, then deserialize the school performed from files, classes, courses, student objects

class School:
    school_name = 'OLDBOY'
    def __init__(self,nickname,addr):
        self.nickname =nickname
        self.addr = addr
        self.classes=[]
    def related_class(self,class_obj):
        self.classes.append(class_obj)
    def tell_class(self):
        print(self.nickname.center(60,'='))
        for class_obj in self.classes:
            class_obj.tell_course()
school_obj1School = ( ' good boy Shanghai campus ' , ' Shanghai ' ) 
school_obj2 = School ( ' Old Boys Beijing campus ' , ' Beijing ' )
 class Class:
     DEF  __init__ (Self, name): 
        self.name = name 
        self.course = None
     DEF related_course (Self, course_obj): 
        self.course = course_obj
     DEF tell_course (Self):
         Print ( ' % S ' % the self.name, End = '')
        self.course.tell_info()
class_obj1 = Class('脱产14期')
class_obj2 = Class('脱产15期')
class_obj3 = Class('脱产29期')
school_obj1.related_class(class_obj1)
school_obj1.related_class(class_obj2)
school_obj2.related_class(class_obj3)
class Course:
    def __init__(self,name,period,price):
        self.name=name
        self.period = period
        self.price = price
    def tell_info (self):
        print('课程名:%s 周期:%s 价格%s' %(self.name,self.period,self.price))
course_obj1= Course('python','6mons','20000')
course_obj2 = Course('linux','5mons','10000')
class_obj1.related_course(course_obj1)
class_obj2.related_course(course_obj2)
class_obj3.related_course(course_obj1)
school_obj1.tell_class()
school_obj2.tell_class()

 

Guess you like

Origin www.cnblogs.com/jingpeng/p/12663897.html