老师,学生,管理员

'''选课系统'''
student_list = []
teacher_list = []
class_list = []


'''学生端'''
def read_all_student():
    if student_list:
        return
    with open('学生信息.txt', 'rt', encoding='utf-8')as f:
        text = f.read()
        if not text:
            return
        texts = text.split(',')
        for i in texts:
            temp = i.split('|')
            d_dic = {}
            d_dic['name'] = temp[0]
            d_dic['password'] = temp[1]
            d_dic['xuan_de_ke'] = temp[2]
            student_list.append(d_dic)


def student_exist(name):
    for student in student_list:
        if student['name'] == name:
            return True
    return False


def write_user(name, password):  # xuan_de_ke
    with open('students.txt', 'a+', encoding='utf-8')as f:
        old = ',%s|%s|%s' % (name, password, [])
        f.write(old)


def student_register():  # 注册
    while True:
        name = input('请输入注册的用户名(按0退出):').strip()
        if name == '0':
            return
        password = input('请输入注册的密码:').strip()
        # xuan_de_ke = [0]
        if name and password:
            print('ok')
            if student_exist(name):
                print('用户名已存在')
                continue
            else:
                print('可以注册')
                if len(password) < 6:
                    print('密码不能少于6位')
                    continue
                else:
                    print('注册成功')
                    write_user(name, password)  # , xuan_de_ke
                    student_list.append({'name': name, 'password': password, 'xuan_de_ke': []})
                    return
        else:
            print('用户名或密码不能为空')


student_login = {}


def student_login_er():  # 登陆
    while True:
        name = input('输入用户名(按0返回上层):')
        if name == '0':
            return
        flag = False
        for stu in student_list:
            if stu['name'] == name:
                flag = True
                break
        else:
            print('用户不存在,请先注册')
            continue
        password = input('请输入密码:')
        for stu in student_list:
            if stu['name'] == name and stu['password'] == password:
                print('登陆成功,欢迎%s' % name)
                student_login['name'] = name
                student_login['password'] = password
                student_login['xuan_de_ke'] = []
                return True

def read_all_class():
    if student_list:
        return
    with open('class_now.txt', 'rt', encoding='utf-8')as f:
        text = f.read()
        if not text:
            return
        texts = text.split(',')
        for i in texts:
            temp = i.split('|')
            d_dic = {}
            d_dic['name'] = temp[0]
            d_dic['time'] = temp[1]
            d_dic['teacher'] = temp[2]
            d_dic['students'] = temp[2]
            class_list.append(d_dic)


# 修改从文件中获取课程
def choose_class():  # 选课
    read_all_class()
    if not student_list:
        print('请先注册或登陆')
        return
    while True:
        for i in class_list:
            print('课程{},{}'.format(i[0], i[1]))
        num = input('请输入选择的课程(输入0退出):')
        if num == '0':
            print('已选择的课程%s' % student_login['xuan_de_ke'])
            return
        for i in class_list:
            if num not in i:
                continue
            else:
                student_login['xuan_de_ke'].append(i)
                for i in student_list:
                    if student_login['name'] == i['name']:
                        i['xuan_de_ke'].append(i)


def look_chosen_class():
    if student_login:
        print(student_login['xuan_de_ke'])


def student():
    read_all_student()
    menu = {'1': student_register,
            '2': student_login,
            '3': choose_class,
            '4': look_chosen_class
            }
    while True:
        print('''----您已进入学生端,请选择您需要的功能----
    1.注册
    2.登录
    3.选课
    4.查看已选课程
    0.退出''')
        choice = input('请输入选择序号(按0返回上层):').strip()
        if choice == '0':
            return
        if choice not in menu:
            print('输入有误,请重新输入')
            continue
        menu[choice]()

'''老师'''


def read_all_teacher():
    if teacher_list:
        return
    with open('老师信息.txt', 'rt', encoding='utf-8')as f:
        text = f.read()
        if not text:
            return
        texts = text.split(',')
        for i in texts:
            temp = i.split('|')
            d_dic = {}
            d_dic['name'] = temp[0]
            d_dic['password'] = temp[1]
            # d_dic['xuan_de_ke'] = temp[2]
            teacher_list.append(d_dic)


def teacher_exist(name):
    for tea in teacher_list:
        if tea['name'] == name:
            return True
    return False


def write_user2(name, password):
    with open('老师信息.txt', 'a+', encoding='utf-8')as f:
        old = ',%s|%s' % (name, password)
        f.write(old)


teacher_login = {}


def teacher_login_er(): #  登陆
    while True:
        name = input('输入用户名(按0返回上层):')
        if name == '0':
            return
        flag = False
        for t in teacher_list:
            if t['name'] == name:
                flag = True
                break
        else:
            print('用户不存在,请先注册')
            continue
        password = input('请输入密码:')
        for t in teacher_list:
            if t['name'] == name and t['password'] == password:
                print('登陆成功,欢迎%s' % name)
                teacher_login['name'] = name
                teacher_login['password'] = password
                teacher_login['class'] = []
                return True


def look_my_class():
    teacher_class = teacher_login['class']
    print(teacher_class)


li = []
def look_student_number():

    print('你该门课程的学生数量为%s' % len(li))


def teacher():
    read_all_teacher()
    menu2 = {'1': teacher_login,
             '2': look_my_class,
             '3': look_student_number}
    while True:
        print('''----您已进入教师端,请选择您需要的功能----
        1.登录
        2.查看我的课程
        3.查看学生人数
        0.退出''')
        choice = input('请输入选择序号(按0返回上层):').strip()
        if choice == '0':
            return
        if choice not in menu2:
            print('输入有误,请重新输入')
            continue
        menu2[choice]()

'''管理员'''

def add_teacher():
    pass


def add_class():
    pass


def admin():
    read_all_teacher()
    menu3 = {'1': add_teacher,
             '2': add_class}
    while True:
        print('''----您已进入教师端,请选择您需要的功能----
            1.添加老师
            2.添加课程
            0.退出''')
        choice = input('请输入选择序号(按0返回上层):').strip()
        if choice == '0':
            return
        if choice not in menu3:
            print('输入有误,请重新输入')
            continue
        menu3[choice]()


method_dic = {'1': student,
              '2': teacher,
              '3': admin}


def main():
    while True:
        print('''
        ------欢迎进入选课系统,请选择进入------
        1.学生
        2.老师
        3.管理员
        0.退出
        ---------------''')
        choice = input('请输入选择序号:').strip()
        if choice == '0':
            return
        if choice not in method_dic:
            print('输入有误,请重新输入')
            continue
        method_dic[choice]()


main()
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值