Python练习题:类与对象

一、题目要求
1. 创建 北京 和 上海 两个校区

  1. 创建 Linux \ Python \ Go 3个课程

  2. 创建 北京校区的Python 16期, Go开发第一期,和上海校区的Linux 10期 班级

  3. 管理员 创建了 北京校区的 学员 小晴 ,并将其 分配 在了 班级 python 16期

  4. 管理员 创建了 讲师 王二 , 并将其分配 给了 班级 python 16期

  5. 讲师 王二 创建 了一条 python 16期的 上课纪录 Day6

  6. 讲师 王二 为Day6这节课 所有的学员 批了作业 ,小晴得了A, 李雷得了C-, 赵帅得了B

  7. 学员李磊 查看了自己所报的所有课程

  8. 学员 李磊 在 查看了 自己在 py16期 的 成绩列表 ,然后退出了

  9. 学员小晴 给 讲师 王二好评

二、code

#Author :ywq

Course_list=[]
class School(object):
    def __init__(self,school_name):
        self.school_name=school_name
        self.students_list=[]
        self.teachers_list=[]
        global Course_list
    def hire(self,obj):
        self.teachers_list.append(obj.name)
        print('[System Notice]:现在雇佣新员工 %s,welcome!' %obj.name)

    def enroll(self,obj):
        self.students_list.append(obj.name)
        print('[System Notice]:学员%s 信息注册成功,ID:%s' %(obj.name,obj.id))


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('[System Notice]:Now, school \'%s\' grade \'%s\' create course \'%s\' ' %(self.school_name,self.code,self.course))

    def course_info(self):
        print('''
        Syllabus(课程大纲) of %s is :
                day 1:
                day 2:
                day 3:
                day 4:
                day 5:
               '''  %self.course)


Python = Grade('BJ',16,'Python')
Go = Grade('BJ',1,'Go')
Linux = Grade('SH',10,'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('-----------My name is %s ,and I am a %s ------------ ' %(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) #保证stu_num_id有两位数,
        #只有一位数时前面填充0,只能对str类型操作
        self.id=stu_id
        self.mark_list={}
    def study(self,course):
        print('------------I come here to learn %s ,ID %s ------------' %(course.course,self.id))
    def pay(self,course):
        print('------------I pay 2000$ for %s ------------' % course.course)
        self.course_list.append(course.course)
    def Praise(self,obj):
        print('------------%s Praise %s:Wonderful! ------------' %(self.name,obj.name))
    def mark_check(self):
        for i in self.mark_list.items():
            print(i)
    def out(self):
        print('[System Notice]:So sadly,the mark of %s  was so bad,he(she) opt out  at last ' %self.name)

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 #保证有两位数,个位数时往前面填充0
        Tea_id=course.school_name +'T'+str(course.code)+str(tea_num_id).zfill(2)
        self.id=Tea_id
    def teach(self,course):
        print('------------I come here to teach guys %s,id %s ------------' %(course.course,self.id))
    def record_mark(self,Date,course,obj,level):
        print('It is  %s \'s mark in the Day %s of the course %s : %s' %(obj.name,Date,course.course,level) )
        obj.mark_list['Day'+Date]=level


a=Students('小晴',21,'W','student',Python)
Python.enroll(a)
a.study(Python)
a.pay(Python)

b=Students('李雷',22,'M','student',Python)
Python.enroll(b)
b.study(Python)
b.pay(Python)

c=Students('赵帅',23,'M','student',Python)
Python.enroll(c)
c.study(Python)
c.pay(Python)



t = Teachers('王二',30,'M','teacher',Python)
Python.hire(t)
t.teach(Python)
t.record_mark('6',Python,a,'A')
t.record_mark('6',Python,c,'B')
t.record_mark('1',Python,b,'C-')
t.record_mark('2',Python,b,'C-')
t.record_mark('3',Python,b,'C-')
t.record_mark('4',Python,b,'C-')
t.record_mark('5',Python,b,'C-')
t.record_mark('6',Python,b,'C-')
print(b.course_list)  #查看已报名课程
b.mark_check()  #评分查询
b.out()
a.Praise(t)

三、运行结果:

[System Notice]:Now, school 'BJ' grade '16' create course 'Python' 
[System Notice]:Now, school 'BJ' grade '1' create course 'Go' 
[System Notice]:Now, school 'SH' grade '10' create course 'Linux' 
-----------My name is 小晴 ,and I am a student ------------ 
[System Notice]:学员小晴 信息注册成功,ID:BJS1601
------------I come here to learn Python ,ID BJS1601 ------------
------------I pay 2000$ for Python ------------
-----------My name is 李雷 ,and I am a student ------------ 
[System Notice]:学员李雷 信息注册成功,ID:BJS1602
------------I come here to learn Python ,ID BJS1602 ------------
------------I pay 2000$ for Python ------------
-----------My name is 赵帅 ,and I am a student ------------ 
[System Notice]:学员赵帅 信息注册成功,ID:BJS1603
------------I come here to learn Python ,ID BJS1603 ------------
------------I pay 2000$ for Python ------------
-----------My name is 王二 ,and I am a teacher ------------ 
[System Notice]:现在雇佣新员工 王二,welcome!
------------I come here to teach guys Python,id BJT1601 ------------
It is  小晴 's mark in the Day 6 of the course Python : A
It is  赵帅 's mark in the Day 6 of the course Python : B
It is  李雷 's mark in the Day 1 of the course Python : C-
It is  李雷 's mark in the Day 2 of the course Python : C-
It is  李雷 's mark in the Day 3 of the course Python : C-
It is  李雷 's mark in the Day 4 of the course Python : C-
It is  李雷 's mark in the Day 5 of the course Python : C-
It is  李雷 's mark in the Day 6 of the course Python : C-
['Python']
('Day5', 'C-')
('Day3', 'C-')
('Day4', 'C-')
('Day1', 'C-')
('Day2', 'C-')
('Day6', 'C-')
[System Notice]:So sadly,the mark of 李雷  was so bad,he(she) opt out  at last 
------------小晴 Praise 王二:Wonderful! ------------
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值