Python入门记录简单项目开发:学生信息管理系统(3):除了排序以外其他模块

这是一个关于学生管理系统的学生信息修改、查找和显示的模块实现。代码包括修改信息、查找信息、显示所有学生信息以及统计整体信息的功能,支持对学生学号、姓名、语文、数学、英语等信息的增删查改,并能计算总分和平均分。
摘要由CSDN通过智能技术生成

基本上这几块都是自己写出来的,功能实现上大体上问题都不大:
修改信息模块:

# 项目名:STUsys
# NAME:modify
# 开发时间:2021/4/26 13:18
#修改信息模块
import mainsystem,show
def modify():
    while True:
        target_id = input('请输入要修改的学生学号:')
        with open(mainsystem.filename,'r',encoding='utf-8') as file:
            student_list = file.readlines()
        with open(mainsystem.filename,'w',encoding='utf-8') as wfile:
            for student in student_list:
                student_dict = dict(eval(student))
                if target_id == student_dict.get('id'):
                    print('找到该学生信息如下:')
                    print(student_dict)
                    student_dict_old = student_dict
                    # print('id'.ljust(10, ' ') + '|', end='')
                    # print('name'.ljust(10, ' ') + '|', end='')
                    # print('chinese'.ljust(10, ' ') + '|', end='')
                    # print('math'.ljust(10, ' ') + '|', end='')
                    # print('english'.ljust(10, ' ') + '|')
                    # for item in student_dict:
                    #     print(str(student_dict.get(item)).ljust(10, ' ') + '|', end='')
                    # break
                    print('请输入需要修改的信息:')
                    for item in student_dict:
                        value_new = input('请输入新的%s信息'%item)
                        student_dict[item] = value_new
                    print('修改后的信息为:%s'%str(student_dict))
                    choice_modify = input('请确认是否要修改信息?y/n')
                    if choice_modify == 'y' or choice_modify == 'Y':
                        wfile.write(str(student_dict)+'\n')
                    else:
                        wfile.write(str(student_dict_old)+'\n')
                else:
                    wfile.write(str(student_dict)+'\n')
            # else:
            #     print('未找到学生信息,请确认学号是否正确并重新输入')
        show.show()
        choice = input('是否要继续修改?y/n')
        if choice == 'y' or choice == 'Y':
            continue
        else:
            break

查找信息模块:

# 项目名:STUsys
# NAME:search
# 开发时间:2021/4/26 13:17
#查找信息模块
import mainsystem
def search():
    while True:
        target_id = input('请输入要查找的学生学号:')
        with open(mainsystem.filename,'r',encoding='utf-8') as file:
            student_list = file.readlines()
        for student in student_list:
            student_dict = dict(eval(student))
            chinese = student_dict.get('chinese')
            math = student_dict.get('math')
            english = student_dict.get('english')
            total = chinese + math + english
            if target_id == student_dict.get('id'):
                print('查找的学生信息如下:')
                print('id'.ljust(10, ' ') + '|', end='')
                print('name'.ljust(10, ' ') + '|', end='')
                print('chinese'.ljust(10, ' ') + '|', end='')
                print('math'.ljust(10, ' ') + '|', end='')
                print('english'.ljust(10, ' ') + '|', end='')
                print('total'.ljust(10, ' ') + '|')
                for item in student_dict:
                    print(str(student_dict.get(item)).ljust(10, ' ') + '|', end='')
                print(str(total).ljust(10, ' ') + '|')
                break
        else:
            print('未找到学生信息,请确认学号是否正确并重新输入')
            continue
        choice = input('是否要继续查找?y/n')
        if choice == 'y' or choice == 'Y':
            continue
        else:
            break


所有学生信息模块:

# 项目名:STUsys
# NAME:show
# 开发时间:2021/4/26 13:20
#全部信息模块
import mainsystem
def show():
    while True:
        #将文件中的信息以列表形式读取出来
        with open(mainsystem.filename,'r',encoding='utf-8') as file:
            student_list = file.readlines()
            pass
        #判断取出的信息是否为空,为空提示无学生信息
        if student_list == []:
            print('404 Not Found')
        else:
            print('id'.ljust(10,' ')+'|',end='')
            print('name'.ljust(10, ' ') + '|',end='')
            print('chinese'.ljust(10, ' ') + '|',end='')
            print('math'.ljust(10, ' ') + '|',end='')
            print('english'.ljust(10, ' ') + '|',end='')
            print('total'.ljust(10, ' ') + '|')
            for student in student_list:
                #在读取的列表中,每一行的学生信息为字符串类型,需要转换成字典类型
                student_dict = dict(eval(student))
                chinese = student_dict.get('chinese')
                math = student_dict.get('math')
                english = student_dict.get('english')
                total = chinese + math + english
                for item in student_dict:
                    print(str(student_dict.get(item)).ljust(10,' ')+'|',end='')
                print(str(total).ljust(10,' ')+'|')
            choice = input('是否要继续查看?y/n')
        if choice == 'y' or choice == 'Y':
            continue
        else:
            break

整体信息模块:

# 项目名:STUsys
# NAME:total
# 开发时间:2021/4/26 13:19
#总体信息模块
import mainsystem
def total():
    while True:
        # 将文件中的信息以列表形式读取出来
        with open(mainsystem.filename, 'r', encoding='utf-8') as file:
            student_list = file.readlines()
            pass
        # 判断取出的信息是否为空,为空提示无学生信息
        if student_list == []:
            print('404 Not Found')
        else:
            chinese_total = math_total = english_total = total_total = 0.0
            for student in student_list:
                # 在读取的列表中,每一行的学生信息为字符串类型,需要转换成字典类型
                student_dict = dict(eval(student))
                chinese = float(student_dict.get('chinese'))
                math = float(student_dict.get('math'))
                english = float(student_dict.get('english'))
                total = float(chinese + math + english)
                chinese_total = chinese_total + chinese
                math_total = math_total + math
                english_total = english_total + english
                total_total = total_total + total
            stu_num = len(student_list)
            chinese_avg = chinese_total / stu_num
            math_avg = math_total / stu_num
            english_avg = english_total / stu_num
            total_avg = total_total / stu_num
            print('number'.ljust(10, ' ') + '|', end='')
            print('CN avg'.ljust(10, ' ') + '|', end='')
            print('math avg'.ljust(10, ' ') + '|', end='')
            print('ENG avg'.ljust(10, ' ') + '|', end='')
            print('total avg'.ljust(10, ' ') + '|')
            print(str(stu_num).ljust(10, ' ') + '|', end='')
            print(str(chinese_avg).ljust(10, ' ') + '|', end='')
            print(str(math_avg).ljust(10, ' ') + '|', end='')
            print(str(english_avg).ljust(10, ' ') + '|', end='')
            print(str(total_avg).ljust(10, ' ') + '|')
        choice = input('是否要继续查看?y/n')
        if choice == 'y' or choice == 'Y':
            continue
        else:
            break

排序这块我打算看下老师写的学习一下算法,上面这些我也还没看课程中写的咋样,看完之后如果有优化也一并在下一篇里一起写吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值