An article teaches you to use Python to realize a student management system

  • 2021-11-30 00:37:51
  • OfStack

Directory title source code: summary

Title

Python has been watching it for almost 34 days, basically giving it to the foundation. Write a management system, follow-up no accident SQL, file storage version will be more.
Thoughts on learning Python:


             Life is too short, I use Python
             Life is too short, I use Python
             Life is too short, I use Python
             Life is too short, I use Python

Python It's so cool 

Source code:

Use Python3


'''
学生成绩管理系统
时间:2021.9.9
作者:sunbeam
'''
import time
import os
student_list = [] #定义1个列表类型全局变量
'''
列表里面存储所有学生信息,列表里面每个元素是1个字典,字典里面存放每1个学生的个人信息,存储结构如下
[(姓名1,年龄1,学号1,手机号码1),(姓名2,年龄2,学号2,手机号码2)......]
'''
def time_day():
        print()
        print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())))

#主菜单界面
def std_menu():
    print("--------欢迎来到sunbeam的第1个python学生管理系统--------")
    print("       1、添加学生信息     2、删除学生信息     ")
    print("       3、查找学生信息     4、修改学生信息     ")
    print("       5、显示所有学生     6、退出系统        ")
    num=int(input("根据需求请输入对应的序号:"))
    return num
#添加学生信息
def std_add():
    while 1:
        std_name = input("请输入要添加的学生的姓名:")
        std_old = input("请输入要添加的学生的年龄:")
        std_id = input("请输入要添加的学生的学号:")
        std_tel = input("请输入要添加的学生的电话号码:")
        global student_list
        # 判断学生是否已存在,如果姓名和学号都重复说明学生存在
        for i in student_list:
            if (i['name'] == std_name) and (i['id'] == std_id):
                print("此学生信息已存在")
                return
        #如果学生信息不存在则添加学生信息
        std_message = {} #创建1个空的字典
        std_message['name']=std_name
        std_message['old']=std_old
        std_message['id']=std_id
        std_message['tel']=std_tel
        student_list.append(std_message)
        text=input("是否继续添加:YES or NO")
        if text=='NO':
            os.system('cls')
            break
        else:
            os.system('cls')
            continue
#查找学生信息
def std_find():
    flag=0
    while 1:
        find_name = input("请输入你要查询的学生的姓名:")
        global student_list
        for i in student_list:
            if (i['name'] == find_name):
                print("查询到如下学生:")
                print("-------------------")
                print(f"姓名:{i['name']}")
                print(f"年龄:{i['old']}")
                print(f"学号:{i['id']}")
                print(f"电话:{i['tel']}")
                print("-------------------")
                flag=1
        if flag==0:
            print("查无此人")
        lk=input("是否继续查找:YES or NO")
        if lk=="NO":
            os.system('cls')
            break
        else:
            os.system('cls')
            continue
#修改学生信息
def std_modify():
    while 1:
        find_name=input("请输入要修改的学生的学号:")
        global student_list
        for i in student_list:
            if (i['id']==find_name):
                print("你要修改的学生信息如下:")
                print("-------------------")
                print(f"姓名:{i['name']}")
                print(f"年龄:{i['old']}")
                print(f"学号:{i['id']}")
                print(f"电话:{i['tel']}")
                print('-----------------')
                while 1:
                    print(" 1、修改学生姓名   2、修改学生年龄 ")
                    print(" 3、修改学生学号   4、修改学生电话 ")
                    modify_num = int(input('请输入要修改的项目序号:'))
                    if modify_num==1:
                        modify_name=input("请输入要修改的学生的姓名:")
                        i['name']=modify_name
                    elif modify_num==2:
                        modify_old=input("请输入要修改的学生的年龄:")
                        i['old']=modify_old
                    elif modify_num==3:
                        modify_id=input("请输入要修改的学生的学号:")
                        i['id']=modify_id
                    else:
                        modify_tel=input("请输入要修改的学的生电话:")
                        i['tel']=modify_tel
                    print("是否继续修改当前学生信息:YES or NO")
                    print('---------------------')
                    modify_flag=input()
                    if modify_flag=="NO":
                        print("-----修改完成-----")
                        break
                    else:
                        continue
                break
        print("是否继续使用修改模块功能:YES or NO")
        lag=input()
        if lag=="YES":
            os.system('cls')
            continue
        else:
            os.system('cls')
            break
#显示所有学生信息
def std_all():
    global student_list
    print('姓名\t年龄\t学号\t电话')
    for i in student_list:
        print(f"{i['name']}\t{i['old']}\t{i['id']}\t{i['tel']}")
#删除函数
def std_delete():
    global student_list
    while 1:
        print("-----------------")
        del_num = input("请输入要删除的学生的学号:")
        for i in student_list:
            if (i['id'] == del_num):
                student_list.remove(i)
                print("删除成功")
                break
            else:
                print("查无此人")
        del_exit=input("是否退出:YES or NO")
        print("-----------------")
        if del_exit=='YES':
            os.system('cls')
            break
        else:
            os.system('cls')
            continue
while 1:
    time_day()
    user_num=std_menu()
    if user_num==1:
        std_add()
    elif user_num==2:
        std_delete()
    elif user_num==3:
        std_find()
    elif user_num==4:
        std_modify()
    elif user_num==5:
        std_all()
    elif user_num==6:
        os.system('cls')
        exit_flag=input("是否退出:YES or NO")
        if exit_flag=='YES':
            print("感谢使用,bey-bey")
            break
        else:
            continue
    else:
        print("输入无用序号,请输入菜单前序号。")

Summarize

This article is here, I hope to give you help, but also hope that you can pay more attention to this site more content!


Related articles: