• 4/7


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

    # # 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()
  • 相关阅读:
    HTML5新特性之离线缓存技术
    摘要
    典藏百度前端面试题
    idea连接mysql数据库
    报错:[stack Error: Can't find Python executable "python"] vue项目npm install
    SVN客户端(小乌龟)checkout(检出)文件(项目)到本地
    java日期Date工具类 日期格式转换
    radio标签 onchange事件
    js 写带有返回值的function遇到的返回值不正常的情况
    读取zip包内根目录文件的文件名
  • 原文地址:https://www.cnblogs.com/bailongcaptain/p/12655542.html
Copyright © 2020-2023  润新知