Python练习题:类与对象
来源:互联网 发布:判断微信浏览器 js 编辑:程序博客网 时间:2024/05/24 05:17
一、题目要求
1. 创建 北京 和 上海 两个校区
创建 Linux \ Python \ Go 3个课程
创建 北京校区的Python 16期, Go开发第一期,和上海校区的Linux 10期 班级
管理员 创建了 北京校区的 学员 小晴 ,并将其 分配 在了 班级 python 16期
管理员 创建了 讲师 王二 , 并将其分配 给了 班级 python 16期
讲师 王二 创建 了一条 python 16期的 上课纪录 Day6
讲师 王二 为Day6这节课 所有的学员 批了作业 ,小晴得了A, 李雷得了C-, 赵帅得了B
学员李磊 查看了自己所报的所有课程
学员 李磊 在 查看了 自己在 py16期 的 成绩列表 ,然后退出了
学员小晴 给 讲师 王二好评
二、code
#Author :ywqCourse_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=00class 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=00class 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]=levela=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 : AIt is 赵帅 's mark in the Day 6 of the course Python : BIt 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! ------------
阅读全文
0 0
- Python练习题:类与对象
- 黑马程序员--oc类与对象的练习题
- java类与对象练习题1--教师学生评分
- java类与对象练习题2--图形面积计算
- Python类与对象
- Python类与对象
- python 对象与类
- Python类与对象
- OC 类和对象 练习题
- Python练习题 类的继承
- python的类与对象
- 关于Python类与对象
- python中的类与对象
- python类与对象part1
- python类与对象part2
- python类与对象part3
- Python 练习题
- python 练习题
- 工作总结
- CSDN-MARKDOWN flowchart.js 流程图详解
- Webpack中 publicPath 跟 path 的区别,个人理解
- CMake找不到opencv库解决办法
- 自动生成简单数学题的小程序范例
- Python练习题:类与对象
- 排序算法
- PAT 甲级 1131. Subway Map (30)
- rosparam和ROS参数服务
- 浅谈美国数学研究的现状
- Pre-reading----End-to-end argument in system design
- Tensorflow(三)- CNN_MNIST
- apt-get update时(0%、100%)[Watting for Headers]停滞
- 学习日记-guid完整代码