Python学生信息管理系统(excel存储)

这是一个关于使用Python进行学生信息管理的系统,目前实现了以txt文件存储数据,但删除和修改功能尚未完善。
摘要由CSDN通过智能技术生成

 删除和修改操作未完成

import row
import xlwt
import os
from openpyxl import *
# 构建workbook对象
workbook = load_workbook('stuinfo.xlsx')
def main():
    while True:
        menu()
        choice = int(input('请选择'))
        if choice in [0, 1, 2, 3, 5, 6, 7, 8, 9, 10]:
            if choice == 0:
                answer = input('您确定要退出系统吗?y/n')
                if answer == 'y' or answer == 'Y':
                    print('感谢您的使用')
                    break
                else:
                    continue
            elif choice == 1:
                insert()
            elif choice == 2:
                total()
            elif choice == 3:
                serch(read_excel_data())
            # elif choice == 4:
            #     delete()
            elif choice == 5:
                modify()
            elif choice == 6:
                sort(read_excel_data())
            elif choice == 7:
                show()
            elif choice == 8:
                all_avg(read_excel_data())
            elif choice == 9:
                subject_avg(read_excel_data())
            elif choice == 10:
                highest(read_excel_data())


def menu():
    print('功能菜单')
    print('0.退出')
    print('1.录入学生信息')
    print('2.查询学生总数')
    print('3.按姓名查找')
    print('4.删除学生信息')
    print('5.修改学生信息')
    print('6.按平均分排序')
    print('7.显示所有学生成绩')
    print('8.查所有学生平均分')
    print('9.每科平均分')
    print('10.查询每科最高分')


def insert():
    student_list = []
    while True:

        name = input('请输入姓名:')
        if not name:
            break

        try:
            english = int(input('请输入英语成绩'))
            python = int(input('请输入Python成绩'))
            java = int(input('请输入java成绩'))
        except:
            print('输入无效,请重新输入')
            continue
        # 将学生信息保存到列表
        stu_info = [name, english, python, java]
        print(stu_info)
        #将学生信息保存到字典中
        # student = {'name': name, 'english': english, 'python': python, 'java': java}
        # print(student)
        #将学生信息添加到列表中
        student_list.append(stu_info)
        # print(student_list)
        # 将从界面输入的数据封装成列表
        stu_info = [name, english, python, java]
        sheet = workbook.active
        row = sheet.max_row + 1
        column = sheet.max_column + 1
        for data_cell in range(1, column):
            sheet.cell(row=row, column=data_cell, value=stu_info[data_cell-1])
        workbook.save(filename='stuinfo.xlsx')
        answer = input('是否继续添加? y/n \n')
        if answer == 'y':
            continue
        else:
            break

    #调用save()函数
    # save(student_list)
    print('学生信息录入完毕')
    # print(student_list)

def save(lst):
    pass
    # try:
    #     stu_txt = open(filename, 'a', encoding='utf-8')
    # except:
    #     stu_txt = open(filename, 'w', encoding='utf-8')
    # for item in lst:
    #     stu_txt.write(str(item)+'\n')
    # stu_txt.close()

def total():

    read_excel_data()
    work_book = load_workbook('stuinfo.xlsx')
    sheet = work_book.active
    stuinfo_list = []
    # print(sheet.max_row)
    print('一共有' + str(sheet.max_row) + '名学生')


def serch(score):
    a = input("请输入学生姓名:")
    flag = False
    for s in score:
        if a == s[0]:
            flag = True
            print('姓名:%s 英语成绩:%.1f  Python成绩:%.1f  Java成绩:%.1f '
                  % (s[0], s[1], s[2], s[3]))
            break
    if flag == False:
        print("未查询到该学生信息")

    # student_query = []
    # while True:
    #     id = ''
    #     name = ''
    #     if os.path.exists('stuinfo.xlsx'):
    #         mode = input('按id查找请输入1,按姓名查找请输入2:')
    #         if mode == '1':
    #             id = input('请输入学生id')
    #         elif mode == '2':
    #             name = input('请输入学生姓名:')
    #         else:
    #             print('您的输入有误,请重新输入')
    #             serch()
    #             rfile = read_excel_data()
    #             print(rfile)
    #             # for item in student:
    #             #     d = dict(eval(item))
    #             #     if id != '':
    #             #         if d['id'] == id:
    #             #             student_query.append(d)  # 查到的学生添加到列表里
    #             
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值