课程管理类的设计

阅读: 评论:0

课程管理类的设计

课程管理类的设计


#父类基类
class Course:lesson={ } #课程列表{'python基础':,'正正','python web':,'宁夫'}__totalSale = 0             #总销量__totalIncome = 0           #总收入lesson_comment = { }  #{'python基础':['讲得好','英文太多听不懂'],'python web':['实用性','老师水平高']}education_year =2022def __init__(self,price):Course.__totalSale=Course.__totalSale+1   #特别注意,这里通过class名称直接访问,self.__totalSale成为实例的私有变量Course.__totalIncome=Course.__totalIncome+price #做收入的累加@classmethod    #返回内部值(作为管理人员查看内部私有属性)def gettotal(cls):return cls.__totalIncome,cls.__totalSale@staticmethoddef aboutWanmen():print('万门是一个多么好的大学!')#声明单课类 lessons 类 继承 Course
class lessons(Course):"""title:课程名称content:课程内容lessontype:课程类型teacher:老师姓名  objisOnline:上架/下架  非参数  成员变量/实例变量"""def __init__(self,title,content,lesson_type,teacher,price):       #teacher和lesson带入对象super().__init__(price)                                       #这种是调用父类原始的构造函数self.title=title                                              #课程名称t=content                                          #课程内容信息self.lesson_type=lesson_type                                  #类型免费/收费acher=teacher.name                                     #老师self.isOnline=Falsedef add_lesson(self):                                             #定义课程上线self.lesson[self.title]&#acherself.isOnline=Truedef remove_lesson(self):                                          #定义课程下线del self.lesson[self.title]self.isOnline=False#声明 课程类型类
class Lesson_type:def __init__(self,type):pe=pe=='免费':self.benefit='可以观看20%的课程'else:self.benefit='可以观看100%的课程'class Teacher:#老师类def __init__(self,name,age):self.name=nameself.age=ageclass comment:def __init__(self,comment,lesson):selfment=commentself.lesson=lesson.titledef add_comment(self):if Course.(self.lesson) == None:               #('key')#字典.get(key)取的是其中的值,若为空Course.lesson_comment[self.lesson]=[selfment]            #dict[key]=value#则将评论直接赋给key所对应的值上else:add_comment = Course.lesson_comment[self.lesson]             #dict[key]获取的值add_comment.append(selfment)                             #给当前的值append数据Course.lesson_comment[self.lesson] = add_comment#1课程类型实例
free=Lesson_type('免费')      #实例
charge=Lesson_type('收费')    #实例#2老师实例
ZZ=Teacher('正正',28)         #实例
NF=Teacher('宁夫',26)         #实例#3具体课程实例
python_basic1 = lessons('python基础1','趣味讲述',free,ZZ,199)               #初始化 带入以上实例objec对象
python_basic2 = lessons('python基础2','趣味讲述',free,ZZ,199)               #初始化 带入以上实例objec对象
python_basic3 = lessons('python基础3','趣味讲述',free,ZZ,199)               #初始化 带入以上实例objec对象
python_web = lessons('python web','网站开发',charge,NF,548)                #初始化 带入以上实例objec对象#课程准备好  开始添加课程
python_basic1.add_lesson()
python_basic2.add_lesson()
python_basic3.add_lesson()
python_web.add_lesson()print(Course.lesson)
#可以下架或移除课程
ve_lesson()
#查看属性
print(python_web.isOnline)
print(Course.lesson)#先有课程后评论,创建评论实例
comment1=comment('非常好的课程',python_basic1)
comment1.add_comment()comment2=comment('通俗的课程',python_basic2)
comment2.add_comment()comment3=comment('代码写的非常好',python_basic3)
comment3.add_comment()comment4=comment('学了就能独立做网站了',python_web)
comment4.add_comment()
print(Course.lesson_comment)#查询类
class BasicInfo(Course):                         #对外可查询接口,数据也是相对公开的,注意这里不能再去初始化父类构造的函数了def __init__(self):                          #这种情况看似平常,实则重写了父类构造的函数,换句话说,不让父类的init执行pass                                     #如果父类执行这里会导致父类的计数器增长def get_lesson(self):print('课程列表',Course.lesson)def get_comment(self):print('课程评价',Course.lesson_comment)def wanmen(self):                            #加一个知识点   super()直接调用父类方法super().aboutWanmen()get_info=BasicInfo()
get_info.wanmen()
_comment()
_comment()
al())

本文发布于:2024-01-28 20:38:27,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170644551010131.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:管理类   课程
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23