自制简单选课系统模拟代码

Posted qianggal

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自制简单选课系统模拟代码相关的知识,希望对你有一定的参考价值。

import pickle
import hashlib
import time

def creat_md5():
    m = hashlib.md5()
    m.update(str(time.time()).encode(‘utf-8‘) )
    return m.hexdigest()
file_id = creat_md5()

def save(end_info):
    with open(file_id,‘wb‘) as f:
        data = pickle.dumps(end_info)
        f.write(data)

class School:
    def __init__(self,addr,name):
        self.addr = addr
        self.name = name
    @classmethod
    def kai_chang_bai(cls):
        print(‘*‘ * 30)
        print(‘--->选课开始‘)
        print(‘下面是校区信息:‘)
        print(msg_school)
    @classmethod
    def school_choosing(cls):
        print(‘-‘ * 30)
        print(‘您选择的学校是 %s 校区的 %s‘ % (sch_s1s2[sch].addr, sch_s1s2[sch].name))
        print(‘-‘ * 30)
        print(‘%s校区的课程有:‘ % sch_s1s2[sch].addr)

class Course:
    def __init__(self,name,period,price,school):
        self.name = name
        self.period = period
        self.price = price
        self.school = school
    @classmethod
    def course_teacher_info(cls):
        print(‘-‘ * 30)
        print(‘您选择的课程是%s,价格%s,时期%s,该课程属于%s校区‘ % (
        msg_course[course].name, msg_course[course].price, msg_course[course].period, msg_course[course].school.addr))
        print(‘-‘ * 30)
        print(‘请选择该课程的老师-->‘)
        print(course_teacher_info[course])

class Teacher:
    def __init__(self,name,age,sex,course,school):
        self.name = name
        self.age = age
        self.sex = sex
        self.course = course
        self.school = school

msg_school = "‘1‘:‘北京odlboy学校‘,
‘2‘:‘上海oldboy学校‘"
msg_course_beijing = "‘1‘:‘课程:python‘,
‘2‘:‘课程:linux‘."
msg_course_shagnhai = "‘3‘:‘课程:go;地址:上海‘"
msg_teacher_python = "‘1‘:‘name:a; age:25; sex:female; course:python; addr:beijing‘,
‘2‘:‘name:b; age:30; "                      "sex:male; course:python; addr:beijing‘"
msg_teacher_linux = "‘3‘:‘name:c; age:40; sex:female; course:linux; addr:beijing‘,
‘4‘:‘name:d; age:35; "                     "sex:male; course:linux; addr:beijing‘"
msg_teacher_go = "‘5‘:‘name:e; age:40; sex:female; course:go; addr:shanghai‘,
‘6‘:‘name:f; age:35; "                  "sex:male; course:go; addr:shanghai‘"

course_info = {
    ‘1‘: msg_course_beijing,
    ‘2‘: msg_course_shagnhai
}

course_teacher_info = {
    ‘1‘: msg_teacher_python,
    ‘2‘: msg_teacher_linux,
    ‘3‘: msg_teacher_go
}

s1 = School(‘北京‘,‘oldboy学校‘)
s2 = School(‘上海‘,‘oldboy学校‘)

sch_s1s2 = {
    ‘1‘:s1,
    ‘2‘:s2
}

t1 = Course(‘python‘,‘5months‘,‘3000yuan‘,s1)
t2 = Course(‘linux‘,‘1month‘,‘1000yuan‘,s1)
t3 = Course(‘go‘,‘5months‘,‘2500yuan‘,s2)

msg_course = {
    ‘1‘:t1,
    ‘2‘:t2,
    ‘3‘:t3
}

msg_course_teacher = {
    ‘a‘:t1,
    ‘b‘:t1,
    ‘c‘:t2,
    ‘d‘:t2,
    ‘e‘:t3,
    ‘f‘:t3
}

tag = True
while tag:
    School.kai_chang_bai()
    sch = input(‘请选择校区‘)
    if sch == ‘1‘:
        while tag:
            School.school_choosing()
            print(course_info[sch])
            course = input(‘请选择你想要学习的课程:‘)
            if course == ‘1‘:
                while tag:
                    Course.course_teacher_info()
                    tch = input(‘请输入老师的名字,字母不区分大小写‘)
                    if tch.lower() == ‘a‘:
                        print(‘-‘ * 30)
                        end_info = ‘您选择的课程是%s,价格%s,时期%s,该课程属于%s校区的%s老师‘                                    % (msg_course[course].name, msg_course[course].price, msg_course[course].period,
                                      msg_course_teacher[tch.lower()].school.addr, tch.lower())
                        print(end_info)
                        save(end_info)
                        print(‘-‘ * 30)
                        tag = False
                        break
                    if tch.lower() == ‘b‘:
                        print(‘-‘ * 30)
                        end_info = ‘您选择的课程是%s,价格%s,时期%s,该课程属于%s校区的%s老师‘                                    % (msg_course[course].name, msg_course[course].price, msg_course[course].period,
                                      msg_course_teacher[tch.lower()].school.addr, tch.lower())
                        print(end_info)
                        save(end_info)
                        print(‘-‘ * 30)
                        tag = False
                        break
                    else:
                        print(‘输入错误,没有该老师,请重新输入‘)
                        continue
                break
            if course == ‘2‘:
                while tag:
                    Course.course_teacher_info()
                    tch = input(‘请输入老师的名字,字母不区分大小写‘)
                    if tch.lower() == ‘c‘:
                        print(‘-‘ * 30)
                        end_info = ‘您选择的课程是%s,价格%s,时期%s,该课程属于%s校区的%s老师‘                                    % (msg_course[course].name, msg_course[course].price, msg_course[course].period,
                                      msg_course_teacher[tch.lower()].school.addr, tch.lower())
                        print(end_info)
                        save(end_info)
                        print(‘-‘ * 30)
                        tag = False
                        break
                    if tch.lower() == ‘d‘:
                        print(‘-‘ * 30)
                        end_info = ‘您选择的课程是%s,价格%s,时期%s,该课程属于%s校区的%s老师‘                                    % (msg_course[course].name, msg_course[course].price, msg_course[course].period,
                                      msg_course_teacher[tch.lower()].school.addr, tch.lower())
                        print(end_info)
                        save(end_info)
                        print(‘-‘ * 30)
                        tag = False
                        break
                    else:
                        print(‘输入错误,没有该老师,请重新输入‘)
                        continue
            else:
                print(‘输入错误,没有该课程,请重新输入‘)
                continue
        break
    if sch == ‘2‘:
        while tag:
            School.school_choosing()
            print(course_info[sch])
            course = input(‘请选择你想要学习的课程:‘)
            if course == ‘3‘:
                while tag:
                    print(‘-‘ * 30)
                    print(‘您选择的课程是%s,价格%s,时期%s,该课程属于%s校区‘ % (msg_course[course].name, msg_course[course].price, msg_course[course].period, msg_course[course].school.addr))
                    print(‘-‘ * 30)
                    print(‘请选择该课程的老师-->‘)
                    print(course_teacher_info[course])
                    tch = input(‘请输入老师的名字,字母不区分大小写‘)
                    if tch.lower() == ‘e‘:
                        print(‘-‘ * 30)
                        end_info = ‘您选择的课程是%s,价格%s,时期%s,该课程属于%s校区的%s老师‘                                    % (msg_course[course].name, msg_course[course].price, msg_course[course].period,
                                      msg_course_teacher[tch.lower()].school.addr, tch.lower())
                        print(end_info)
                        save(end_info)
                        print(‘-‘ * 30)
                        tag = False
                        break
                    if tch.lower() == ‘f‘:
                        print(‘-‘ * 30)
                        end_info = ‘您选择的课程是%s,价格%s,时期%s,该课程属于%s校区的%s老师‘                                    % (msg_course[course].name, msg_course[course].price, msg_course[course].period,
                                      msg_course_teacher[tch.lower()].school.addr, tch.lower())
                        print(end_info)
                        save(end_info)
                        print(‘-‘ * 30)
                        tag = False
                        break
                    else:
                        print(‘输入错误,没有该老师,请重新输入‘)
                        continue
                break
            else:
                print(‘输入错误,没有该课程,请重新输入‘)
                continue
        break
    else:
        print(‘输入错误,请重新输入!‘)
        continue

print(‘您的最终信息‘)
with open(file_id,‘rb‘) as file:
    d = pickle.loads(file.read())
    print(d)

  

以上是关于自制简单选课系统模拟代码的主要内容,如果未能解决你的问题,请参考以下文章

自制操作系统09中断的代码实现

数据库实验(学生选课系统)

python模拟选课系统

JavaWeb选课系统

自制操作系统03读取硬盘中的数据

JAVA | 学生选课系统