• Python之旅的第30天(过程记录,选课系统的基本实现)


      感觉按照我目前的状态和速度,要想明天做出来,简直是痴人说梦,目前紧缺的知识是文件处理和哈希加密那部分,可以针对性补习一下。

      其实主要是在最后一节课里面说,这个搞不懂没法开始网络编程,所以就还是努力做出来,果然自学还是存在练习不足的问题。

      下面我来简单介绍一下自己今天做了啥?

      目前做的结构:

     bin.py文件内容:

    import os,sys,pickle
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    sys.path.append(BASE_DIR)
    from src.services import teacher
    from src.services import student
    from src.services import admin
    
    if __name__ == '__main__':
        msg = '1.管理员登录
    '
              '2.学生登录
    '
              '3.教师登录
    '
        print(msg)
    
        choice_dict = {
            '1': admin.login ,
            '2': student.login ,
            '3': teacher.login
        }
        while True:
            choice = input('>>>请选择进入界面')
            if len(choice) == 0 or choice not in choice_dict:
                continue
            else:
                break
        res = choice_dict[choice]()
        print(res)

    此时我惊讶的发现,自己搞了这么久就弄了个学校类出来,哈哈哈哈~

    果然前面很多白学了,忘光了

    class School:
        '用于创建学校,包含地址,应该需要被课程所继承,同时可以用来关联课程'
        def __init__(self, name, addr):
            self.name = name
            self.addr =addr
    
        def show_school(self):
            # 用于查看学校信息
            print('学校名称:%s'%self.name)
            print('学校地址:%s'%self.addr)
    
        def creat_course(self,course_name,time,price):
            # 用于学校开设课程
            self.__dict__[course_name] = {'课程周期':time , '课程价格':price}
            res = '已完成%s %s的 %s课程的开设'%(self.name,self.addr,course_name) + '
    课程周期:%s 课程价格: %s'%(time,price)
            return res
    
        def show_course(self):
            for k , v in self.__dict__.items():
                # print('zhixing')
                # print(type(v))
                if type(v) is dict:
                    print('课程名称:%s'%k)
                    print('课程周期: ',v['课程周期'])
                    print('课程价格: ',v['课程价格'])
    
        def get_price(self):
            # show_course(self)   # 貌似这么调用还不行
            # 看来在获取价格之前得自己调取输出课程内容
            # 但是这里应该会有别的办法,暂时先空着,应该会有从其他地方调用来减少操作的方法,
            # 或者在获得费用之前直接展示,相关内容写在学生逻辑中
            course_name = input('请输入你想查看的课程:>>>')
            # 用于获取课程价格,便于后期学生缴费使用
            return self.__dict__[course_name]['课程价格']
    
        def delete_course(self,course_name):
            if course_name in self.__dict__:
                del self.__dict__[course_name]
                print('%s 课程已成功删除'%course_name)
            else:
                print('所选课程不存在!!!')
    
    def creat_school():
        name = ''
        addr = ''
        while True:
            xuexiao_name = input('>>>学校名称').strip()
            print('学校名称>>>%s'%xuexiao_name)
            is_ok = input('>>>请确认学校名称(Y/N)').strip()
            if is_ok.upper() == 'Y':
                name = xuexiao_name
                break
            else:
                continue
        while True:
            xuexiao_addr = input('>>>学校地址').strip()
            print('学校地址>>>%s'%xuexiao_addr)
            is_ok = input('>>>请确认学校地址(Y/N)').strip()
            if is_ok.upper() == 'Y':
                addr = xuexiao_addr
                break
            else:
                continue
        return School(name,addr)
    
    def admin_creat_course(School):
        course_name = ''
        time = ''
        price = 0
        while True:
            kecheng_name = input('>>>课程名称').strip()
            print('课程名称>>>%s'%kecheng_name)
            is_ok = input('>>>请确认课程名称(Y/N)').strip()
            if is_ok.upper() == 'Y':
                course_name = kecheng_name
                break
            else:
                continue
        while True:
            kecheng_time = input('>>>课程周期').strip()
            print('课程周期>>>%s'%kecheng_time)
            is_ok = input('>>>请确认课程名称(Y/N)').strip()
            if is_ok.upper() == 'Y':
                time = kecheng_time
                break
            else:
                continue
        while True:
            kecheng_price = input('>>>课程价格').strip()
            print('课程价格>>>%s'%kecheng_price)
            is_ok = input('>>>请确认课程名称(Y/N)').strip()
            if is_ok.upper() == 'Y':
                price = kecheng_price
                break
            else:
                continue
        return School.creat_course(course_name,time,price)
    
    
    
    
    if __name__ == '__main__':
        # s1 = School('清华','北京校区')
        # py = s1.creat_course('python','one month',2000)
        # print(py)
        # print(s1.__dict__)
        # s1.show_course()
        # print(s1.get_price())
        s1 = creat_school()
        s1.show_school()
        admin_creat_course(s1)
        print(s1.__dict__)
        s1.show_course()

    感觉就算只写了这个,也是感觉不满意,应该有很多可以进行优化啊,哎。。。。

    晚安了,最近有点恢复加班狗的趋势,在我学习大业未成之前,大吼一声“不~~~要~~~啊~~~”

  • 相关阅读:
    一类分治问题
    [POI2005]DWU-Double-row
    [SCOI2007]降雨量
    [POI2007]ODW-Weights(贪心)
    bzoj3427小P的牧场(斜率优化dp)
    UVA10559 Blocks(区间dp)
    LOJ6089 小Y的背包计数问题(根号优化背包)
    [APIO2008]免费道路(生成树)
    bzoj4383(拓扑排序)
    [HEOI2014]平衡(整数划分数)
  • 原文地址:https://www.cnblogs.com/xiaoyaotx/p/12556303.html
Copyright © 2020-2023  润新知