欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

学习记录:python实现一个简易的校园管理系统7.19

程序员文章站 2022-11-05 19:59:01
实现一个简易的校园管理系统,使用容器保存学生数据和老师数据。学员信息有: 姓名, 年龄, 性别,班级,学号讲师信息有:姓名, 年龄, 性别, 课程, 工号(可以使用列表嵌套字典的方式保存学生和讲师数据例:stulist=[{“name”:“zhang”,“age”:18,…},{“name”:“zhang”,“age”:18,…},{“name”:“zhang”,“age”:18,…}])1.程序开启时,提示用户输入用户名密码,如果输入错误,则重新输入,最多不超过3次。(每一个具体功能用函数单...

实现一个简易的校园管理系统,使用容器保存学生数据和老师数据。

学员信息有: 姓名, 年龄, 性别,班级,学号
讲师信息有:姓名, 年龄, 性别, 课程, 工号

(可以使用列表嵌套字典的方式保存学生和讲师数据
例:stulist=[{“name”:“zhang”,“age”:18,…},{“name”:“zhang”,“age”:18,…},{“name”:“zhang”,“age”:18,…}]

1.程序开启时,提示用户输入用户名密码,如果输入错误,则重新输入,最多不超过3次。
(每一个具体功能用函数单独编写,然后统一调用)

2.输入正确后,显示以下菜单并完善其功能:
显示所有学生信息
显示所有老师信息
学校招生(增加学生信息)
学校招聘讲师(增加老师信息)
学生毕业(根据学号删除学生信息)
讲师离职(根据工号删除老师信息)
根据学号修改学生信息
根据姓名修改讲师信息
退出程序

#创建学生列表
student1={"姓名":"林俊杰","年龄":18,"性别":"男","班级":2,"学号":1001}
student2={"姓名":"周杰伦","年龄":20,"性别":"男","班级":3,"学号":1002}
student3={"姓名":"张学友","年龄":19,"性别":"男","班级":5,"学号":1003}
student4={"姓名":"刘德华","年龄":21,"性别":"男","班级":4,"学号":1004}
student5={"姓名":"汪三峰","年龄":22,"性别":"男","班级":1,"学号":1005}

#创建老师列表
teacher1={"姓名":"小红红","年龄":18,"性别":"女","课程":"语文","工号":666}
teacher2={"姓名":"林小雪","年龄":18,"性别":"女","课程":"数学","工号":667}
teacher3={"姓名":"林美丽","年龄":18,"性别":"女","课程":"英语","工号":668}
teacher4={"姓名":"赵家家","年龄":18,"性别":"女","课程":"语文","工号":669}
teacher5={"姓名":"李小雅","年龄":18,"性别":"女","课程":"地理","工号":670}
#分别创建两个空的字典来保存学生和老师的数据
studentup ={}
teacherup = {}
#把学生列表和老师列表作字典合并方便读取
stulist1=[student1,student2,student3,student4,student5]
tealist2=[teacher1,teacher2,teacher3,teacher4,teacher5]
#创建登录用户列表
user1 = {"用户名":"老王","密码":"123"}
user2 = {"用户名":"老五","密码":"123"}
#列表嵌套字典,方便读取数据
users =[user1,user2]
#登录 用户名 密码
def login():
    count = 0
    while 1==1:
        get_key = input("请输入用户名:")
        get_password = input("请输入密码:")
        back = None
        for i in users:
            if get_key == i["用户名"] and get_password == i["密码"]:
                print("密码正确!")
                back = {"用户名":get_key,"密码":get_password}
            
        if back == None:
            count += 1
            if count == 3:
                print("你输入三次密码错误!")
                break
            else:
                print("您已经输入错误",count,"次,还有",3-count,"次机会!")
                continue
        else:
            count=0
            interface() #调用功能界面
            select1()   #调用选择功能
            break
#功能介绍界面
def interface():
    print('''
    ------------>校园管理系统<------------
    |
    ------>1.显示所有学生信息 
    |
    ------>2.显示所有老师信息 
    |
    ------>3.学校招生(增加学生信息)
    |
    ------>4.学校招聘讲师(增加老师信息)
    |
    ------>5.学生毕业(根据学号删除学生信息)
    |
    ------>6.讲师离职(根据工号删除老师信息)
    |
    ------>7.根据学号修改学生信息 
    |
    ------>8.根据姓名修改讲师信息 
    |         
    ------>9.退出程序 
    |                      
    --------------------------------------
        ''')
#选择功能
def select1():  
    while 1==1:
        select = int(input("请输入选择编码:"))
        if select == 1:
            studentlist() 
        elif select == 2:
            teacherlist()
        elif select == 3:
            studentadd()
        elif select == 4:
            teacheradd()
        elif select == 5:
            studentdelete() 
        elif select == 6:
            teacherdelete()
        elif select == 7:
            studentchange()
        elif select == 8:
            teacherchange()
        elif select == 9:
            print("退出成功!")
            break
        else:
            print("请输入正确的编号!")

#显示所有学生信息
def studentlist():
    for i in stulist1:
        print(i)

#显示所有老师信息
def teacherlist():
    for i in tealist2:
        print(i)

#增加学生信息
def studentadd():
    msg2 = 0
    while 1==1:
        studentnumber = int(input("请输入你的学号:"))
        for i in stulist1:

            if studentnumber == i["学号"]:
                msg2 = 1
                break
            else:
                msg2 = 0
                break
        
        if msg2 == 1:
            print("学号存在,请重新输入!")
            continue
        elif msg2 == 0:
            name = input("请输入你的名字:")
            year = input("请输入你的年龄:")
            sex = input("请输入你的性别:")
            studentclass = input("请输入你的班级:")
            studentup["姓名"] = name
            studentup["年龄"] = year
            studentup["性别"] = sex
            studentup["班级"] = studentclass
            studentup["学号"] = studentnumber
            stulist1.append(studentup)
            while 1==1:
                select = input("是否继续添加(y/n):")
                if select == "y":
                    break
                elif select == "n":
                    break
                else:
                    print("请输入(y/n)")
            if select == "y":
                pass
            elif select == "n":
                interface()
                break

#增加老师信息

def teacheradd():
    msg2 = 0
    while 1==1:
        teachernumber = int(input("请输入你的工号:"))
        for i in tealist2:
            if teachernumber == i["工号"]:
                msg2 = 1
                break
            else:
                msg2 = 0
                break
        
        if msg2 == 1:
            print("工号存在,请重新输入!")
            continue
        elif msg2 == 0:
            name = input("请输入你的名字:")
            year = input("请输入你的年龄:")
            sex = input("请输入你的性别:")
            teacherclass = input("请输入你的课程:")
            teacherup["姓名"] = name
            teacherup["年龄"] = year
            teacherup["性别"] = sex
            teacherup["课程"] = teacherclass
            teacherup["工号"] = teachernumber
            tealist2.append(teacherup)
            while 1==1:
                select = input("是否继续添加(y/n):")
                if select == "y":
                    break
                elif select == "n":
                    break
                else:
                    print("请输入(y/n)")
            if select == "y":
                pass
            elif select == "n":
                interface()
                break
#根据学号删除学生信息
def studentdelete():
    print("5")
    while 1==1:
        a = 0
        get = int(input("请输入学号:"))
        for i in stulist1:
            if get == i["学号"]:
                stulist1.remove(stulist1[a])
                print("删除学号:"+str(get)+"成功!")
                break 
            a += 1
        if get == i["学号"]:
            break    

#根据工号删除老师信息       
def teacherdelete():
    print("6")
    while 1==1:
        a = 0
        get = int(input("请输入工号:"))
        for i in tealist2:
            if get == i["工号"]:
                tealist2.remove(tealist2[a])
                print("删除工号:"+str(get)+"成功!")
                break 
            a += 1
        if get == i["工号"]:
            break
#估计学生学号修改学生信息
def studentchange():
    print("7")
    while 1==1:
        a = 0
        get = int(input("请输入学号:"))
        for i in stulist1:
            if get == i["学号"]:
                name = input("修改姓名:")
                year = input("修改年龄:")
                sex = input("修改性别:")
                studentclass = input("修改班级:")

                stulist1[a]["姓名"] = name
                stulist1[a]["年龄"] = year
                stulist1[a]["性别"] = sex
                stulist1[a]["班级"] = studentclass
                
                print("----修改成功!----")
                time.sleep(1)
                interface()
                break
            a += 1
        if get == i["学号"]:
            break 

#估计学生学号修改学生信息
def teacherchange():
    print("8")
    while 1==1:
        a = 0
        get = int(input("请输入工号:"))
        for i in tealist2:
            if get == i["工号"]:
                name = input("修改姓名:")
                year = input("修改年龄:")
                sex = input("修改性别:")
                teacherclass = input("修改课程:")

                tealist2[a]["姓名"] = name
                tealist2[a]["年龄"] = year
                tealist2[a]["性别"] = sex
                tealist2[a]["课程"] = teacherclass
                
                print("----修改成功!----")
                time.sleep(1)
                interface()
                break
            a += 1
        if get == i["工号"]:
            break     
login()
'''
优化字典嵌套字典 利用学号作为键值保存(学生姓名成绩)数据修改更加方便
'''
student= {}
while True:
    option=int(input("请输入操作数字:"))
    if option==1:
        stu = {} #保存信息
        while True:
            id = input("请输入要添加学生学号:")
            if id in student.keys():
                print("学号%s已存在!" % id)
                continue
            else:
                stu['id']=id
                name = input("请输入添加学生姓名:")
                stu['name'] = name
                scores = input("请输入要添加学生成绩:")
                stu['scores'] = scores
                student[id] = stu #学号作为键值
                print(student)
                break

本文地址:https://blog.csdn.net/qq_26086231/article/details/107450385

相关标签: python