4/7

孤人 提交于 2020-04-07 20:53:11

选课系统项目中涉及到诸多数据与功能,要求引入面向对象的思想对其进行高度整合

# # 1、学校数据与功能整合class school:​    def __init__(self, school_name, school_adress):        self.name = school_name        self.adrss = school_adress​    def info(self):        print(f'校名{self.name},地址{self.adrss}')​​school.obj = school('oldboy', '上海青浦')school.info(school.obj)​​# # 2、课程数据与功能进行整合class course:    def __init__(self, name, period, price):        self.name = name        self.period = period        self.price = price​    def info(self):        print(f'课程{self.name},课程周期{self.period},课程价格{self.price}')​​course_obj = course('课程A', '14天', '20块')course_obj.info()​​# # 3、学生数据与功能进行整合class classmates:    def __init__(self, name, age, id, school, gender):        self.name = name        self.age = age        self.id = id        self.school = school        self.gender = gender​    def info(self):        print(f'姓名:{self.name}年龄:{self.age}学号:{self.id}学校:{self.school}性别:{self.gender}')​wangmou = classmates('王某','18','151617','上海小天才幼儿园','男')wangmou.info()​# # 4、讲师数据与功能进行整合class teacher:    def __init__(self,name,age,salary,level):        self.name = name        self.age = age        self.salary = salary        self.level = level​    def info(self):        print(f'讲师姓名:{self.name} 讲师年龄:{self.age}  讲师薪资:{self.salary}  讲师等级:{self.level} ')​teacher_obj = teacher('egon','78','588888','888')teacher_obj.info()​# # 5、班级数据与功能进行整合class grade:    def __init__(self,name,area):        self.name = name        self.area = area​    def info(self):        print(f'班级姓名:{self.name} 所属校区:{self.area} ')​grad_obj = grade('向日葵班','上海校区')grad_obj.info()
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!