student_info.py

本文介绍了一个简单的学生信息管理系统,包括添加、展示、删除、修改学生信息等功能,并提供了按成绩和年龄排序的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import time

def show_menu():
    print("\n\t\t            \033[1;31mCHOICE MENU\033[0m")
    print('\t\t+--------------------------------------+')
    print('\t\t| 1) Add Student Info.                 |')
    print('\t\t| 2) Show All Info.                    |')
    print('\t\t| 3) Delete Info.                      |')
    print('\t\t| 4) Modify Info.                      |')
    print('\t\t| 5) Sort Info. with Score(High to Low)|')
    print('\t\t| 6) Sort Info. with Score(Low to High)|')
    print('\t\t| 7) Sort Info. with Age(Old to Young) |')
    print('\t\t| 8) Sort Info. with Age(Young to Old) |')
    print('\t\t| 9) Quit System                       |')
    print('\t\t+--------------------------------------+')

def input_student(lst):
    print("\n\t\t\033[1;32mYou are inputting student's info.\033[0m")
    item_lst = ['name','age','score'] 
    while True:
        info_dict = {}
        for i in item_lst:
            temp = input("\t\tPlease input student's \033[1;31m%s\033[0m:" % i)
            if temp.isnumeric():
                temp = int(temp)
            info_dict[i] = temp
            if info_dict['name'] == '':
                return 
        print()
        lst.append(info_dict)

def output_student(lst):
    print("\n\t\t\t\033[1;32mStudents' Info. List\033[0m")
    item_lst = ['name','age','score']
    string1 = ''
    string2 = ''
    for i in range(len(item_lst)):
        string1 += '+' + '-'*10
        string2 += '|'+ item_lst[i].center(10)
    print('\t\t' + string1 + '+\t\t\t')
    print('\t\t' + string2 + '|\t\t\t')
    print('\t\t' + string1 + '+\t\t\t')
    for info in lst:
        string3 = ''
        for i in range(len(item_lst)):
            string3 += '|' + str(info[item_lst[i]]).center(10)
        print('\t\t' + string3 + '|\t\t\t')
    print('\t\t' + string1 + '+\t\t\t')

def delete_student(lst):
    print("\n\t\t\033[1;32mYou are deleting a student's info.\033[0m")
    while True:
        name = input("\t\tPlease input the student's \033[1;31mname\033[0m:")
        for info in lst:
            if info['name'] == name:
                lst.remove(info)
                print("\t\t\t\033[1;31mDeletion Successful!\033[0m")
                conti = input("\t\t\033[1;34mInput 'c' to continue deleting:\033[0m")
                if conti != 'c':
                    print("\t\t\t\033[1;31mDeletion end!\033[0m")
                    return
                else:
                    break
        else:
            print("\t\t\033[1;31mCan't Find the Student's Info.\033[0m")

def modify_student(lst):
    print("\n\t\t\033[1;32mYou are modifying a student's info.\033[0m")
    name = input("\t\tPlease input the student's \033[1;31mname\033[0m:")
    for info in lst:
        if info['name'] == name:
            while True:
                temp = input("\t\tPlease input the \033[1;31mitem\033[0m to modify:")
                if temp not in info:
                    print("\t\t\033[1;31mItem Error, Modification Interrupted!\033[0m")
                    continue
                value = input("\t\tThe \033[1;31mnew value\033[0m is:")
                info[temp] = value
                print("\t\t\t\033[1;31mModification Successful!\033[0m")
                conti = input("\t\t\033[1;34mInput 'c' to continue modifying:\033[0m")
                if conti != 'c':
                    print("\t\t\t\033[1;31mModification end!\033[0m")
                    return
    else:
        print("\t\t\033[1;31mCan't Find the Student's Info.\033[0m")

def score_sort_high(lst):
    new_lst = sorted(lst,key=lambda i: i['score'],reverse=True)
    output_student(new_lst)
    print("\t\tSorted with score (high to low)")

def score_sort_low(lst):
    new_lst = sorted(lst,key=lambda i: i['score'])
    output_student(new_lst)
    print("\t\tSorted with score (low to high)")

def age_sort_old(lst):
    new_lst = sorted(lst,key=lambda i: i['age'],reverse=True)
    output_student(new_lst)
    print("\t\tSorted with age (old to young)")

def age_sort_young(lst):
    new_lst = sorted(lst,key=lambda i: i['age'])
    output_student(new_lst)
    print("\t\tSorted with age (young to old)")

def main():
    lst = []
    while True:
        time.sleep(2)
        show_menu()
        n = input("\t\t\033[1;31mYour Choice:\033[0m")
        if n == '1':
            input_student(lst)
        elif n == '2':
            output_student(lst)
        elif n == '3':
            delete_student(lst)
        elif n == '4':
            modify_student(lst)
        elif n == '5':
            score_sort_high(lst)
        elif n == '6':
            score_sort_low(lst)
        elif n == '7':
            age_sort_old(lst)
        elif n == '8':
            age_sort_young(lst)
        elif n == '9':
            return 
        else:
            print("\t\t\t\033[1;31mEROOR INPUT!\033[0m")

if __name__ == '__main__':
    main()

import tkinter as tk from tkinter import messagebox from tkinter import ttk # 添加学生信息 def add_student_info(): global entry_name,entry_student_id,entry_sco,entry_lx name = entry_name.get() # 获取姓名输入框内容 student_id = entry_id.get() # 获取学号输入框内容 sco = entry_sco.get() # 获取成绩输入框内容 lx = entry_lx.get() # 获取联系方式输入框内容 with open("student.txt", "a") as file: # 以追加模式打开文件 file.write(f"姓名: {name}, 学号: {student_id}, 成绩: {sco},联系方式:{lx}\n") # 写入格式化数据 messagebox.showinfo("成功", "学生信息添加成功!") # 显示成功提示 # 清空输入框 entry_name.delete(0, tk.END) entry_id.delete(0, tk.END) entry_sco.delete(0, tk.END) entry_lx.delete(0, tk.END) # 删除学生信息 def delete_student_info(): student_id_to_delete = entry_delete.get() # 获取要删除的学号 lines = [] # 存储文件内容的列表 with open("student.txt", "r") as file: # 读取模式打开文件 lines = file.readlines() # 读取所有行 found = False # 删除标志位 with open("student.txt", "w") as file: # 写入模式打开文件(清空原内容) for line in lines: if f"学号: {student_id_to_delete}" not in line: # 保留非目标学号的行 file.write(line) else: found = True # 标记已找到并删除 entry_delete.delete(0, tk.END) # 清空输入框 # 根据删除结果显示消息 if found: messagebox.showinfo("成功", "学生信息删除成功!") else: messagebox.showerror("错误", "该学生不存在!") # 修改学生信息 def modify_student_info(): student_id_to_modify = entry_modify_id.get() # 获取要修改的学号 found = False # 修改标志位 updated_lines = [] # 存储更新后的行 with open("student.txt", "r") as file: # 读取文件 lines = file.readlines() # 获取所有行 for line in lines: if f"学号: {student_id_to_modify}" in line: # 找到目标学号的行 found = True # 使用新输入创建新行 updated_lines.append(f"姓名: {entry_modify_name.get()}, 学号: {entry_modify_student_id.get()}, 成绩: {entry_modify_sco.get()}, 联系方式: {entry_modify_lx.get()}\n") else: updated_lines.append(line) # 保留其他行 with open("student.txt", "w") as file: # 写入模式打开文件 for line in updated_lines: file.write(line) # 写入更新后的内容 # 清空所有修改相关的输入框 entry_modify_id.delete(0, tk.END) entry_modify_name.delete(0, tk.END) entry_modify_student_id.delete(0, tk.END) entry_modify_sco.delete(0, tk.END) entry_modify_lx.delete(0, tk.END) # 显示修改结果 if found: messagebox.showinfo("成功", "学生信息修改成功!") else: messagebox.showerror("错误", "该学生不存在!") # 查询学生信息 def find_student_info_by_id(): student_id = entry_search.get() # 获取查询学号 found = False # 查询标志位 with open("student.txt", "r") as file: # 读取文件 lines = file.readlines() # 获取所有行 for line in lines: if f"学号: {student_id}" in line: # 查找匹配学号 found = True messagebox.showinfo("成功", f"找到对应学生信息:\n{line.strip()}") # 显示学生信息 break # 找到后跳出循环 if not found: # 未找到时的处理 messagebox.showerror("错误", "未找到该学生信息,请检查输入的学号是否正确。") # 根据成绩排序 def sort_students_by_sco(): with open("student.txt", "r") as file: # 读取文件 lines = file.readlines() # 获取所有行 students = [] # 存储解析后的学生数据 for line in lines: parts = line.strip().split(", ") # 分割每行数据 name = parts[0].split(": ")[1] # 提取姓名 student_id = parts[1].split(": ")[1] # 提取学号 sco = float(parts[2].split(": ")[1]) # 提取成绩并转为浮点数 lx = (parts[3].split(": ")[1]) # 提取联系方式 students.append({'name': name, 'id': student_id, 'sco': sco, 'lx': lx}) # 添加到列表 # 按成绩降序排序 sorted_students = sorted(students, key=lambda x: x['sco'], reverse=True) sorted_info = "" # 存储排序结果字符串 for student_info in sorted_students: # 格式化每个学生信息 sorted_info += f"姓名: {student_info['name']} 学号: {student_info['id']} 成绩: {student_info['sco']} 联系方式: {student_info['lx']}\n" # 显示排序结果对话框 messagebox.showinfo("学生信息按成绩降序排序", sorted_info) def student(): root = tk.Tk() # 创建主窗口 root.title("学生信息管理系统") # 设置窗口标题 notebook = ttk.Notebook(root) # 创建选项卡控件 notebook.pack() # 将选项卡放置到窗口 # 创建五个选项卡框架 tab1 = ttk.Frame(notebook) tab2 = ttk.Frame(notebook) tab3 = ttk.Frame(notebook) tab4 = ttk.Frame(notebook) tab5 = ttk.Frame(notebook) notebook.add(tab1, text="添加学生信息") notebook.add(tab2, text="删除学生信息") notebook.add(tab3, text="修改学生信息") notebook.add(tab4, text="查询学生信息") notebook.add(tab5, text="按成绩排序") # 添加学生信息选项卡 tk.Label(tab1, text="姓名:").pack() global entry_name entry_name = tk.Entry(tab1) entry_name.pack() tk.Label(tab1, text="学号:").pack() global entry_id entry_id = tk.Entry(tab1) entry_id.pack() tk.Label(tab1, text="成绩:").pack() global entry_sco entry_sco = tk.Entry(tab1) entry_sco.pack() tk.Label(tab1, text="联系方式:").pack() global entry_lx entry_lx = tk.Entry(tab1) entry_lx.pack() tk.Button(tab1, text="添加", command=add_student_info).pack() # 删除学生信息选项卡 tk.Label(tab2, text="输入要删除的学生学号:").pack() global entry_delete entry_delete = tk.Entry(tab2) entry_delete.pack() tk.Button(tab2, text="删除", command=delete_student_info).pack() # 修改学生信息选项卡 tk.Label(tab3, text="输入要修改的学生学号:").pack() global entry_modify_id entry_modify_id = tk.Entry(tab3) entry_modify_id.pack() tk.Label(tab3, text="新姓名:").pack() global entry_modify_name entry_modify_name = tk.Entry(tab3) entry_modify_name.pack() tk.Label(tab3, text="新学号:").pack() global entry_modify_student_id entry_modify_student_id = tk.Entry(tab3) entry_modify_student_id.pack() tk.Label(tab3, text="新成绩:").pack() global entry_modify_sco entry_modify_sco = tk.Entry(tab3) entry_modify_sco.pack() tk.Label(tab3, text="新联系方式:").pack() global entry_modify_lx entry_modify_lx = tk.Entry(tab3) entry_modify_lx.pack() tk.Button(tab3, text="确认修改", command=modify_student_info).pack() # 查询学生信息选项卡 tk.Label(tab4, text="请输入学生学号:").pack() global entry_search entry_search = tk.Entry(tab4) entry_search.pack() tk.Button(tab4, text="查询", command=find_student_info_by_id).pack() # 按成绩排序选项卡 tk.Button(tab5, text="显示", command=sort_students_by_sco).pack() root.mainloop() #启动主事件循环 代码运行出现File “E:\66\学生管理系统\学生管理系统\Student.py”, line 108, in sort_students_by_sco sco = float(parts[2].split(": ")[1]) # 提取成绩并转为浮点数 ValueError: could not convert string to float: ‘2,联系方式:2’
最新发布
07-04
/home/aistudio /home/aistudio/PaddleDetection Warning: Unable to use numba in PP-Tracking, please install numba, for example(python3.7): `pip install numba==0.56.4` Warning: Unable to use numba in PP-Tracking, please install numba, for example(python3.7): `pip install numba==0.56.4` Warning: Unable to use MOT metric, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics Warning: Unable to use MCMOT metric, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics W0614 14:48:53.736156 263603 gpu_resources.cc:119] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 12.0, Runtime API Version: 11.8 W0614 14:48:53.737314 263603 gpu_resources.cc:164] device: 0, cuDNN Version: 8.9. [06/14 14:48:56] ppdet.utils.checkpoint INFO: The shape [365] in pretrained weight yolo_head.pred_cls.0.bias is unmatched with the shape [4] in model yolo_head.pred_cls.0.bias. And the weight yolo_head.pred_cls.0.bias will not be loaded [06/14 14:48:56] ppdet.utils.checkpoint INFO: The shape [365, 576, 3, 3] in pretrained weight yolo_head.pred_cls.0.weight is unmatched with the shape [4, 576, 3, 3] in model yolo_head.pred_cls.0.weight. And the weight yolo_head.pred_cls.0.weight will not be loaded [06/14 14:48:56] ppdet.utils.checkpoint INFO: The shape [365] in pretrained weight yolo_head.pred_cls.1.bias is unmatched with the shape [4] in model yolo_head.pred_cls.1.bias. And the weight yolo_head.pred_cls.1.bias will not be loaded [06/14 14:48:56] ppdet.utils.checkpoint INFO: The shape [365, 288, 3, 3] in pretrained weight yolo_head.pred_cls.1.weight is unmatched with the shape [4, 288, 3, 3] in model yolo_head.pred_cls.1.weight. And the weight yolo_head.pred_cls.1.weight will not be loaded [06/14 14:48:56] ppdet.utils.checkpoint INFO: The shape [365] in pretrained weight yolo_head.pred_cls.2.bias is unmatched with the shape [4] in model yolo_head.pred_cls.2.bias. And the weight yolo_head.pred_cls.2.bias will not be loaded [06/14 14:48:56] ppdet.utils.checkpoint INFO: The shape [365, 144, 3, 3] in pretrained weight yolo_head.pred_cls.2.weight is unmatched with the shape [4, 144, 3, 3] in model yolo_head.pred_cls.2.weight. And the weight yolo_head.pred_cls.2.weight will not be loaded [06/14 14:48:56] ppdet.utils.checkpoint INFO: Finish loading model weights: /home/aistudio/.cache/paddle/weights/ppyoloe_crn_m_obj365_pretrained.pdparams [06/14 14:48:56] ppdet.slim.distill_model INFO: Student model has loaded pretrain weights! [06/14 14:48:57] ppdet.utils.checkpoint INFO: The shape [80] in pretrained weight yolo_head.pred_cls.0.bias is unmatched with the shape [4] in model yolo_head.pred_cls.0.bias. And the weight yolo_head.pred_cls.0.bias will not be loaded [06/14 14:48:57] ppdet.utils.checkpoint INFO: The shape [80, 960, 3, 3] in pretrained weight yolo_head.pred_cls.0.weight is unmatched with the shape [4, 960, 3, 3] in model yolo_head.pred_cls.0.weight. And the weight yolo_head.pred_cls.0.weight will not be loaded [06/14 14:48:57] ppdet.utils.checkpoint INFO: The shape [80] in pretrained weight yolo_head.pred_cls.1.bias is unmatched with the shape [4] in model yolo_head.pred_cls.1.bias. And the weight yolo_head.pred_cls.1.bias will not be loaded [06/14 14:48:57] ppdet.utils.checkpoint INFO: The shape [80, 480, 3, 3] in pretrained weight yolo_head.pred_cls.1.weight is unmatched with the shape [4, 480, 3, 3] in model yolo_head.pred_cls.1.weight. And the weight yolo_head.pred_cls.1.weight will not be loaded [06/14 14:48:57] ppdet.utils.checkpoint INFO: The shape [80] in pretrained weight yolo_head.pred_cls.2.bias is unmatched with the shape [4] in model yolo_head.pred_cls.2.bias. And the weight yolo_head.pred_cls.2.bias will not be loaded [06/14 14:48:57] ppdet.utils.checkpoint INFO: The shape [80, 240, 3, 3] in pretrained weight yolo_head.pred_cls.2.weight is unmatched with the shape [4, 240, 3, 3] in model yolo_head.pred_cls.2.weight. And the weight yolo_head.pred_cls.2.weight will not be loaded [06/14 14:48:57] ppdet.utils.checkpoint INFO: Finish loading model weights: /home/aistudio/.cache/paddle/weights/ppyoloe_plus_crn_x_80e_coco.pdparams [06/14 14:48:57] ppdet.slim.distill_model INFO: Teacher model has loaded pretrain weights! Traceback (most recent call last): File "/home/aistudio/PaddleDetection/tools/train.py", line 212, in <module> main() File "/home/aistudio/PaddleDetection/tools/train.py", line 197, in main cfg = build_slim_model(cfg, FLAGS.slim_config) File "/home/aistudio/PaddleDetection/ppdet/slim/__init__.py", line 53, in build_slim_model model = PPYOLOEDistillModel(cfg, slim_cfg) File "/home/aistudio/PaddleDetection/ppdet/slim/distill_model.py", line 326, in __init__ super(PPYOLOEDistillModel, self).__init__(cfg=cfg, slim_cfg=slim_cfg) File "/home/aistudio/PaddleDetection/ppdet/slim/distill_model.py", line 82, in __init__ self.distill_loss = self.build_loss(self.distill_cfg) File "/home/aistudio/PaddleDetection/ppdet/slim/distill_model.py", line 86, in build_loss return create(distill_cfg.distill_loss) File "/home/aistudio/PaddleDetection/ppdet/core/workspace.py", line 292, in create return cls(**cls_kwargs) TypeError: DistillPPYOLOELoss.__init__() got an unexpected keyword argument 'feat_distill_norm' 怎么回事怎么解决问题出在哪?
06-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值