Home  >  Article  >  Backend Development  >  How to use Python to implement a fully functional student management system.

How to use Python to implement a fully functional student management system.

WBOY
WBOYforward
2023-05-08 23:58:151833browse

Function Description

1. Divided into two interfaces: (1) Login and registration interface (2) Student management system interface
2. The login function is the same as the previously released library management system, login After success, you can enter the student management system interface, which will not be described here
3. System functions (1) Add student information (2) Delete student information (3) Modify student information (4) Query student information (5) Display all students Information (6) Exit
4. Many places have been optimized and improved, such as module import, login and registration, and carriage return without modification. The entire program code is about 200 lines.

Note: The code is divided into two modules and needs to be started in the student_main module. The student_main module is only responsible for input operations, while the student_tools module is responsible for specific student information system operation implementation functions. So everyone remember to create two .py files when copying the code.

The complete code is as follows

student_main module content code:

import student_tools

user=['wangtaotao']
pwd=['123456']

#登录
def denglu():
    users = input("请输入您的用户名:")
    pwds = input("请输入您的密码:")
    if users in user and pwds in pwd:
        student()
    else:
        print("账号或密码不正确,请重新输入")

#注册
def zhuce():
    users=input("请输入您要注册的用户名:")
    pwds=input("请输入您要注册的密码:")
    user.append(users)
    pwd.append(pwds)
    print()
    print("注册成功!")
    print()

#登录界面
def dljiemian():

    while True:
        print("---------------------------")
        print("    学生管理系统登陆界面 V1.0  ")
        print("                           ")
        print("        1:登   录           ")
        print("        2:注   册           ")
        print("        3:退   出           ")
        print("                           ")
        print("---------------------------")
        xx=input("请输入您的选择:")
        #1.登录
        if xx=='1':
            denglu()
        elif xx=='2':
        #2.注册
            zhuce()
        elif xx=='3':
        #3.退出
            print()
            print("成功退出!")
            print()
            break
        else:
            print("输入错误,请重新输入")
#学生管理系统
def student():
    while True:
        #调用student_tools模块中的界面函数
        student_tools.jiemian()
        x=input("请输入您的选择:")
        #添加学生
        if x=='1':
            student_tools.add()
        #删除学生
        elif x=='2':
            student_tools.dele()
        #修改学生
        elif x=='3':
            student_tools.xiugai()
        #查询学生
        elif x=='4':
            student_tools.find()
        #显示所有学生
        elif x=='5':
            student_tools.showall()
        #退出学生管理系统,返回上一层登录界面系统
        elif x=='6':
            print()
            print("成功退出学生管理系统!")
            break
        else:
            print()
            print("输入错误,请重新输入")
            print()

#调用最先执行的登录界面函数
dljiemian()

student_tools module content code:

student_list=[]

student_dict={}

#学生管理系统界面
def jiemian():
    print("---------------------------")
    print("      学生管理系统 V1.0")
    print("                           ")
    print("      1:添加学生"            )
    print("      2:删除学生"            )
    print("      3:修改学生"            )
    print("      4:查询学生"            )
    print("      5:显示所有学生"         )
    print("      6:退出系统"            )
    print("                           ")
    print("---------------------------")


#添加学生
def add():
    name=input("请输入录入学生姓名:")
    cls=input("请输入学生班级:")
    age=input("请输入录入学生年龄:")
    phone=input("请输入录入学生手机号:")
    addr=input("请输入录入学生家庭住址:")

    student_dict={"name":name,"class":cls,"age":age,"phone":phone,"address":addr}

    student_list.append(student_dict)
    print()
    print("-----添加学生信息界面-----")
    print()
    print("姓名\t\t","班级\t\t","年龄\t\t","电话号\t\t","家庭住址\t\t")
    for student_dict_1 in student_list:
        print("%s\t\t%s\t\t%s\t\t%s\t\t%s" %(student_dict_1["name"],
                                             student_dict_1["class"],
                                             student_dict_1["age"],
                                             student_dict_1["phone"],
                                             student_dict_1["address"]))
    print()
    print("录入成功!")
    print()

#删除学生
def dele():
    name_del=input("请输入想要删除的学生姓名:")
    for student_dict_1 in student_list:
        if name_del in student_dict_1["name"]:
            student_list.remove(student_dict_1)
            print()
            print("删除%s信息成功!" % name_del)
            print()
            break
    else:
        print()
        print("您输入的学生姓名错误,请重新输入")
        print()
#修改学生
def xiugai():
    name_xiugai=input("请输入想要修改的学生姓名:")


    for student_dict_1 in student_list:

        if name_xiugai == student_dict_1["name"]:
            print()
            print("-----修改界面-----")
            print()
            print("姓名\t\t", "班级\t\t", "年龄\t\t", "电话号\t\t", "家庭住址\t\t")
            print("%s\t\t%s\t\t%s\t\t%s\t\t%s" %(student_dict_1["name"],
                                                 student_dict_1["class"],
                                                 student_dict_1["age"],
                                                 student_dict_1["phone"],
                                                 student_dict_1["address"]))
            #回车不修改

            student_dict_1["name"]=new_input(student_dict_1["name"],"请输入修改后的学生姓名[回车不修改]:")
            student_dict_1["class"]=new_input(student_dict_1["class"],"请输入修改后的学生班级[回车不修改]:")
            student_dict_1["age"]=new_input(student_dict_1["age"],"请输入修改后的学生年龄[回车不修改]:")
            student_dict_1["phone"]=new_input(student_dict_1["phone"],"请输入修改后的学生手机号[回车不修改]:")
            student_dict_1["address"]=new_input(student_dict_1["address"],"请输入修改后的学生家庭地址[回车不修改]:")
            print()
            print("修改成功!")
            print()
            break
    else:
        print()
        print("您输入的学生姓名错误,请重新输入")
        print()

#查找学生
def find():
    find_name=input("请输入需要查找的学生姓名:")
    for student_dict_1 in student_list:

        if find_name == student_dict_1["name"]:
            print()
            print("-----查询结果界面-----")
            print()
            print("姓名\t\t", "班级\t\t", "年龄\t\t", "电话号\t\t", "家庭住址\t\t")
            print("%s\t\t%s\t\t%s\t\t%s\t\t%s" % (student_dict_1["name"],
                                                  student_dict_1["class"],
                                                  student_dict_1["age"],
                                                  student_dict_1["phone"],
                                                  student_dict_1["address"]))
        else:
            print()
            print("-----查询结果界面-----")
            print()
            print("无此学生信息")

#显示所有学生信息
def showall():
    print()
    print("-----显示所有学生信息-----")
    print()
    print("姓名\t\t", "班级\t\t", "年龄\t\t", "电话号\t\t", "家庭住址\t\t")
    for student_dict_1 in student_list:
        print(student_dict_1)
        print("%s\t\t%s\t\t%s\t\t%s\t\t%s" % (student_dict_1["name"],
                                              student_dict_1["class"],
                                              student_dict_1["age"],
                                              student_dict_1["phone"],
                                              student_dict_1["address"]))
#设置用户不输入内容返回原值,输入内容返回新内容
def new_input(yuanzhi,message):
    input_str=input(message)

    if len(input_str)>0:
        return input_str
    else:
        return yuanzhi

The above is the detailed content of How to use Python to implement a fully functional student management system.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete