从0基础学习Python(08)[案例][学生管理系统]

从0基础学习Python (Day8)

学生管理系统-----[案例]

前言[仔细看前言,略微重要]

​ 就开发而言,我们在做一个项目之前应该先做好准备工作,首先应该先要知道我们做的这个项目,是用来干嘛的,客户需要这个项目来完成什么功能,这就需要跟客户进行一个[需求分析],来确定我们要做的项目主要是那个方向,在确定了需求之后接下来根据需求我们需要有这个项目一个完整的框架和需要实现这个功能的大纲,也就是我们的[系统功能分析],这个系统功能分析完整的列出我们要做的程序框架,还有需要实现的功能,与客户进行一起商讨后才开始程序的开发,下面我将把完整的从[需求分析]到[系统的功能分析]以及代码的书写详细的介绍。

[=程序开发前的准备工作开始 =]

需求分析

作用:

客户和开发人员双向的一个说明书

对于客户而言:这个需求分析就是一个基本的说明书,和客户进行协商(产品经理主要就是和客户对接)

对于开发人员而言:这个需求分析就是系统开发的一个核心思想路线,开发工作主要就是围绕着需求分析进行开展(关键字(变量、函数、类名称)之类)

系统的功能分析

系统功能

  1. 添加学生

    检查添加的信息中的唯一值(标识列)-学号(stu_no)

    如果存在

    ​ 提示:该学号已存在

    如果不存在

    ​ 引导用户输入学生的详细信息

    ​ 保存数据

  2. 删除学生

  3. 修改学生

  4. 查询学生

  5. 展现所有学生信息

系统分析

学生信息

​ 学号、姓名、年龄、Python成绩

数据的保存方式

​ 数据保存在什么地方?取决于数据的重要层次

​ 只能从元祖、列表、集合、字典中选择字典:使用学号作为每个学生字典的键值

系统架构搭建

​ 1.定义函数、显示操作菜单,并且监听用户的选择

​ 2.通过用户的选择进行条件判断

按照需求分析实现功能

[=程序开发前的准备工作结束 =]

[=↓↓↓程序开发工作开始↓↓↓ =]

注:实现了信息的载入,以及对学生信息的相关操作,还有操作后的循环,每一个操作对应一个函数,使用前面的知识可独立完成~~~

[以下为本博客博主自主开发,供参考]

import os

# 创建总字典储存学生信息
# all_dict = {"1000": {"no": "1000", "name": "李华", "age": "23", "fs": 99}}
# with open("SMData.txt", "w",encoding="utf-8") as all_data:
#     all_data.write(str(all_dict))
all_dict = {}
#载入函数,目前的知识还不能实现,可以省略此功能
def load_fz():
    if os.path.exists("SMData.txt"):
        with open("SMData.txt", "r", encoding="utf-8")as file:
            ret = file.read()
            global all_dict
            all_dict = eval(ret)
        print("数据加载完成.......")
        print(all_dict)
load_fz()

while True:
    print("==============================================")
    print("-----------头发又掉了一根管理系统 v1.0----------")
    print("==============================================")
    print("1.添加学生")
    print("2.删除学生")
    print("3.修改学生信息")
    print("4.查询学生信息")
    print("5.展现所有学生信息")
    print("6.平均成绩")
    print('7.成绩及格率')
    print("8.保存数据")
    print("==============================================")


    def tj_fz():
        with open("SMData.txt", "w",encoding="utf-8") as file:
            file.write(str(all_dict))

  
    def aaa_fz():
        while True:
            xh_xh1 = input("请输入学号:")
            if xh_xh1 in all_dict:
                print("该学生已存在")
                continue
            else:
                name1 = input("请输入姓名:")
                age1 = int(input("请输入年龄:"))
                fs1 = int(input("请输入成绩:"))
                all_dict1 = {'no': xh_xh1, 'name': name1, 'age': age1, 'fs': fs1}
                all_dict.setdefault(xh_xh1, all_dict1)
            print("学生信息已添加")
            print("学号%s||姓名%s||年龄%s||成绩%s" % (xh_xh1, name1, age1, fs1))
            return


    def bbb_fz():
        while True:
            xh_xh2 = input("请输入学号:")
            if xh_xh2 in all_dict:
                del all_dict[xh_xh2]
                print("删除成功")
                print(all_dict)
                return
            else:
                print("该学生已删除")
                continue


    def ccc_fz():
        while True:
            xh_xh3 = input("请输入你要更改信息学生的学号")
            if xh_xh3 not in all_dict:
                print("该学生不在我们系统中")
                continue
            else:
                name2 = input("请输入更改姓名:")
                age2 = int(input("请输入更改年龄:"))
                fs2 = input("请输入更改成绩:")
                all_dict[xh_xh3] = {"no": xh_xh3, "name": name2, "age": age2, "fs": fs2}
                print("更改完成")
            print(all_dict)
            return


    def ddd_fz():
        while True:
            xh_xh4 = input("请输入你要查询的学号:")
            if xh_xh4 in all_dict:
                print("学号%s||姓名%s||年龄%s||成绩%s" % (
                all_dict[xh_xh4]["no"], all_dict[xh_xh4]["name"], all_dict[xh_xh4]["age"], all_dict[xh_xh4]["fs"]))
                return
            else:
                print("查无此人")
                continue


    def eee_fz():
        print("=======全部信息如下嘤嘤嘤========")
        for xh_xh5 in all_dict.values():
            print("学号%s||姓名%s||年龄%s||成绩%s" % (xh_xh5["no"], xh_xh5["name"], xh_xh5["age"], xh_xh5["fs"]))


    def fff_fz():
        list = []
        a = 0
        for a1 in all_dict.values():
            list.append(a1["fs"])
            for a2 in list:
                a += a2
            print("平均分为:", a / len(all_dict))


    def ggg_fz():
        list = []
        a = 0
        for stu_dict in all_dict.values():
            list.append(stu_dict["fs"])
        for aaa in list:
            if aaa >= 60:
                a += 1
        aww = a / len(all_dict) * 100
        print("及格率为%.2f%%" % aww)


    xh_xh = int(input("请输入你要进行的操作对应的序号:"))
    if xh_xh == 1:
        aaa_fz()
    elif xh_xh == 2:
        bbb_fz()
    elif xh_xh == 3:
        ccc_fz()
    elif xh_xh == 4:
        ddd_fz()
    elif xh_xh == 5:
        eee_fz()
    elif xh_xh == 6:
        fff_fz()
    elif xh_xh == 7:
        ggg_fz()
    elif xh_xh == 8:
        tj_fz()
    else:
        print("你输入的不对奥")
        print("           ,             ")
        print("          / \            ")
        print("         p   !           ")
        print("         ; : ;           ")
        print("         | : |           ")
        print("         l ; l           ")
        print("         l ; l           ")
        print("         I ; I           ")
        print("         I ; I           ")
        print("         I ; I           ")
        print("         I ; I           ")
        print("         d | b           ")
        print("         H | H           ")
        print("         H | H           ")
        print("         H I H           ")
        print(" ,;,     H I H        ,;,")
        print(";H@H;    ;_H_;,     ;H@H;")
        print(" `\Y/d_,;|4H@HK|;,_b\Y/' ")
        print("  '\;MMMMM$@@@$MMMMM;/'  ")
        print("    ~~~*;!8@8!;*~~~      ")
        print("         ;888;           ")
        print("         ;888;           ")
        print("         ;888;           ")
        print("         ;888;           ")
        print("         d8@8b           ")
        print("         O8@8O           ")
        print("         T808T           ")
        print("          `~`            ")

        continue
    yh = int(input("输入1继续,输入其他字符结束"))
    if yh == 1:
        continue
    else:
        print("再见,奥里给!!!!!!!!!!!!!!!!!!!!!!")
    break
   

Day8-------END

猜你喜欢

转载自blog.csdn.net/weixin_47766667/article/details/107584474