day23课程对象的定义与使用

课程对象的定义与使用

class School:
    school_name = 'oldboy'

    def __init__(self, nickname, addr):
        self.nickname = nickname
        self.addr = addr
        self.classes = []

    def ralated_class(self, class_obj):
        self.classes.append(class_obj)

    def tell_class(self):
        print(self.nickname.center(50, '='))
        for class_obj in self.classes:
            class_obj.tell_course()
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 ' % self.name, end='')
        self.course.tell_info()
class Student:
    _name = '名称'

    def __init__(self, name):
        self.name = name
        print(f'学生姓名是:{name}')

    def Choose_class(self):
        pass
class Course:

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

    def related_students(self, student_obj):
        pass

    def tell_info(self):
        print('<课程名:%s  周期:%s 价格:%s>' % (self.name, self.period, self.price))
class Teacher:
    _name = '名称'

    def __init__(self):
        pass

创建校区

school_obj1 = School('老男孩上海校区', '上海')
school_obj2 = School('老男孩帝都校区', '北京')

创建班级

class_obj1 = Class('脱产14期')
class_obj2 = Class('脱产15期')
class_obj3 = Class('脱产29期')

创建课程

course_obj1 = Course('python全栈开发', '6mons', 20000)
course_obj2 = Course('linux运维', '5mons', 18000)
course_obj3 = Course('python全栈开发', '6mons', 20000)

为班级开设课程

class_obj1.related_course(course_obj1)
class_obj2.related_course(course_obj2)
class_obj3.related_course(course_obj3)

为学校开设班级

school_obj1.ralated_class(class_obj1)
school_obj1.ralated_class(class_obj2)
school_obj2.ralated_class(class_obj3)

school_obj1.tell_class()
school_obj2.tell_class()
print(school_obj1.__dict__)#字典中班级的value绑定了两个班级对象
print(class_obj1 .__dict__)#字典中的课程绑定了一个课程对象
print(course_obj1.__dict__)
#class_obj1.tell_course()
#class_obj2.tell_course()
#class_obj3.tell_course()
=====================老男孩上海校区======================
脱产14<课程名:python全栈开发  周期:6mons 价格:20000>
脱产15<课程名:linux运维  周期:5mons 价格:18000>
=====================老男孩帝都校区======================
脱产29<课程名:python全栈开发  周期:6mons 价格:20000>
{'nickname': '老男孩上海校区', 'addr': '上海', 'classes': [<__main__.Class object at 0x0000010FC816A970>, <__main__.Class object at 0x0000010FC816AA30>]}
{'name': '脱产14期', 'course': <__main__.Course object at 0x0000010FC816AAF0>}
{'name': 'python全栈开发', 'period': '6mons', 'price': 20000}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值