zoukankan      html  css  js  c++  java
  • Python---面向对象---修学校

    一、创建北京和成都两个校区:

      1、创建LinuxPython两个课程

      2、创建北京校区的Python 3期课程和成都校区的Linux 1期课程

      3、管理员创建了北京校区的学员小张,并将其分配在了Python 3期

      4、管理员创建了讲师小周,并将其分配了Python 3期

      5、讲师小周创建了一条Python 3期的上课记录Day02

      6、讲师小周为Day02这节课所有的学院批改了作业,小张得了A,小王得了B

      7、学员小张查看了自己所报的课程

      8、学员小张在查看了自己在Python3的成绩列表然后退出了

      9、学院小张给了讲师小周好评

    ------------------------------------------------------------------

    Course_list = []
    class School(object):
        def __init__(self, school_name):
            self.school_name = school_name
            self.student_list = []
            self.teachers_list = []
           
            global Course_list
           
        def hire(self, obj):
            self.teacher_list.append(obj.name)
            print("我们现在聘请一个新老师{}".format(obj.name))
       
        def enroll(self, obj):
            self.student_list.append(obj.name)
            print("我们又有了一个新学员{}".format(obj.name))
    class Grade(School):
        def __init__(self, school_name, grade_code, grade_course):
            super(Grade, self).__init__(school_name)
            self.code = grade_code
            self.course = grade_course
            self.members = []
            Course_list.append(self.course)
           
            print("我们现在有了{}的{}的{}".format(self.school_name, self.code, self.course))
           
        def course_info(self):
            print("课程大纲{} 是 day01, day02, day03".format(self.course))
           
    Python = Grade("BJ",3,"Python")
    Linux = Grade("CD",1,"Linux")
    class School_member(object):
        def __init__(self, name, age, sex, role):
            self.name = name
            self.age = age
            self.sex = sex
            self.role = role
            self.course_list=[]
           
            print("我叫{}, 我是一个{}".format(self.name, self.role))
       
    stu_num_id = 00
    class Students(School_member):
        def __init__(self, name, age, sex, role, course):
            super(Students, self).__init__(name, age, sex, role)
            global stu_num_id
            stu_num_id += 1
            stu_id = course.school_name + "S" + str(course.code) + str(stu_num_id).zfill(2)
            #zfill 填充的作用,当只有一位数时前面填充0,只能对str类型做操作
           
            self.id = stu_id
            self.mrk_list={}
           
        def study(self, course):
                print("我来这里学习{}课,我的学号是{}".format(course, course, self, id))
               
        def pay(self, course):
                print("我交了1000块钱{}".format(course.course))
                self.course_list.append(course.course)
               
        def Praise(self, obj):
                print("{}觉得{}课真棒".format(self.name, obj.name))
               
        def mark_check(self):
                for i in self.mark_list.items():
                    print(i)
                   
        def out(self):
                print("我离开了")
    tea_num_id = 00          
    class Teachers(School_member):
        def __init__(self, name, age, sex, role, course):
            super(Teachers, self).__init__(name, age, sex, role)
            global tea_num_id
            tea_num_id += 1
            tea_id = course.school_name + "T" + str(course.code) + str(tea_num_id).zfill(2)
            # zfill  填充的作用  当只有一位数时前面填充0,只能对str类型做操作
            self.id = tea_id
       
        def teach(self, course):
            print("我来这里讲{}门课,我的id是{}".format(course, course, self,id))
           
        def record_mark(self, Date, course, obj, level):
            obj.mark_list['Day'+Date] = level
    a = Students("小张", 18, "M", "student", Python)
    Python.enroll(a)
    a.study(Python)
    a.pay(Python)
    b = Students("小王", 22, "F", "student", Python)
    Python.enroll(a)
    b.study(Python)
    b.pay(Python)

    c = Teachers("小周", 30, "M", "teacher", Python)
    Python.hire(c)
    c.teach(Python)
    t.record_mark("1", Python, a, "A")
    t.record_mark("1", Python, b, "B")
    t.record_mark("2", Python, a, "A")
    t.record_mark("2", Python, b, "B")
    print(b.course_list)
    b.mark_check()
    b.out()
  • 相关阅读:
    分布式事务处理总结
    职业生涯的第一个三年
    Linux 启动SVN服务
    TensorFlow入门:安装常用的依赖模块
    TensorFlow入门:mac 安装 TensorFlow
    shiro 配置导图
    spring集成JPA的三种方法配置
    tomcat server 报错之 More than the maximum allowed number of cookies
    Jquery系列:checkbox 获取值、选中、设置值、事件监听等操作
    [转]Tomcat优化之内存、并发、缓存
  • 原文地址:https://www.cnblogs.com/niaocaizhou/p/10982732.html
Copyright © 2011-2022 走看看