python實(shí)現(xiàn)簡(jiǎn)單的學(xué)生成績(jī)管理系統(tǒng)
本文實(shí)例為大家分享了python實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
需求:
代碼:
import os filename = 'student.txt' def main(): ? ? while True: ? ? ? ? menu() ? ? ? ? choice = int(input("請(qǐng)選擇:")) ? ? ? ? if choice in [0,1,2,3,4,5,6,7]: ? ? ? ? ? ? if choice==0: ? ? ? ? ? ? ? ? answer = input("你確定要退出嗎?y/n") ? ? ? ? ? ? ? ? if answer =='y' or answer =='Y': ? ? ? ? ? ? ? ? ? ? print("謝謝使用!") ? ? ? ? ? ? ? ? ? ? break ? ? ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? ? ? continue ? ? ? ? ? ? elif choice ==1: ? ? ? ? ? ? ? ? insert() ? ? ? ? ? ? elif choice ==2: ? ? ? ? ? ? ? ? search() ? ? ? ? ? ? elif choice ==3: ? ? ? ? ? ? ? ? delete() ? ? ? ? ? ? elif choice ==4: ? ? ? ? ? ? ? ? modify() ? ? ? ? ? ? elif choice ==5: ? ? ? ? ? ? ? ? sort() ? ? ? ? ? ? elif choice ==6: ? ? ? ? ? ? ? ? total() ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? show() # 菜單 def menu(): ? ? print("====================學(xué)生成績(jī)管理系統(tǒng)=========================") ? ? print("======================功能菜單==============================") ? ? print("\t\t1、錄入學(xué)生信息") ? ? print("\t\t2、查找學(xué)生信息") ? ? print("\t\t3、刪除學(xué)生信息") ? ? print("\t\t4、修改學(xué)生信息") ? ? print("\t\t5、排序") ? ? print("\t\t6、統(tǒng)計(jì)學(xué)生人數(shù)") ? ? print("\t\t7、顯示所有學(xué)生信息") ? ? print("\t\t0、退出系統(tǒng)") ? ? print("--------------------------------------------------------------") # 插入 def insert(): ? ? student_list=[] ? ? while True: ? ? ? ? id = input('請(qǐng)輸入ID(如1001):') ? ? ? ? if not id: ? ? ? ? ? ? break ? ? ? ? name = input('請(qǐng)輸入姓名:') ? ? ? ? if not name: ? ? ? ? ? ? break ? ? ? ? try: ? ? ? ? ? ? english=int(input("input english grade:")) ? ? ? ? ? ? python=int(input("input python grade:")) ? ? ? ? ? ? java=int(input("input java grade:")) ? ? ? ? except: ? ? ? ? ? ? print("輸入成績(jī)無(wú)效!重新輸入!") ? ? ? ? ? ? continue ? ? ? ? student = {'id':id,'name':name,'english':english,'python':python,'java':java} ? ? ? ? student_list.append(student) ? ? ? ? answer = input("是否繼續(xù)添加信息!?:'y/n'") ? ? ? ? if answer == 'y': ? ? ? ? ? ? continue ? ? ? ? else: ? ? ? ? ? ? break ? ? # 調(diào)用save函數(shù)將其保存在文本當(dāng)中 ? ? save(student_list) ? ? print("學(xué)生信息錄入成功!") # 保存 def save(lst): ? ? 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 search(): ? ? while True: ? ? ? ? student_name = input("請(qǐng)輸入你要查找的學(xué)生姓名:") ? ? ? ? if student_name: ? ? ? ? ? ? if os.path.exists(filename): ? ? ? ? ? ? ? ? with open(filename,'r',encoding='utf-8') as rfile: ? ? ? ? ? ? ? ? ? ? student_old = rfile.readlines() ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? student_old = [] ? ? ? ? ? ? if student_old: ? ? ? ? ? ? ? ? d = {} ? ? ? ? ? ? ? ? flag = False ? ? ? ? ? ? ? ? for item in student_old: ? ? ? ? ? ? ? ? ? ? d = dict(eval(item)) ? ? ? ? ? ? ? ? ? ? if d['name'] == student_name: ? ? ? ? ? ? ? ? ? ? ? ? flag = True ? ? ? ? ? ? ? ? ? ? ? ? student_show(d) ? ? ? ? ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? ? ? ? ? pass ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? print("無(wú)學(xué)生信息,請(qǐng)?zhí)砑樱?) ? ? ? ? ? ? if flag: ? ? ? ? ? ? ? ? print("查詢成功") ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? print("查詢失敗") ? ? ? ? else: ? ? ? ? ? ? print("沒有輸入學(xué)生姓名!") ? ? ? ?? ? ? ? ? answer = input("請(qǐng)問是否繼續(xù)查詢:y/n") ? ? ? ? if answer == "y": ? ? ? ? ? ? continue ? ? ? ? else: ? ? ? ? ? ? break # 展示個(gè)人信息 def student_show(dic): ? ? format_title = '{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}' ? ? print(format_title.format('ID','姓名','英語(yǔ)成績(jī)','python成績(jī)','java成績(jī)','總成績(jī)')) ? ? format_data = '{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}' ? ? print(format_data.format(dic.get('id'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('name'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('english'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('python'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('java'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? int(dic.get('english'))+int(dic.get('python'))+int(dic.get('java')), ? ? ? ? ? ? ? ? ? ? ? ? ? ? )) # 刪除 def delete(): ? ? while True: ? ? ? ? student_id = input("請(qǐng)輸入要?jiǎng)h除的學(xué)生ID:") ? ? ? ? if student_id: ? ? ? ? ? ? if os.path.exists(filename): ? ? ? ? ? ? ? ? with open(filename,'r',encoding='utf-8') as file: ? ? ? ? ? ? ? ? ? ? student_old = file.readlines() ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? student_old=[] ? ? ? ? ? ? flag = False ? ? ? ? ? ? if student_old: ? ? ? ? ? ? ? ? with open(filename,'w',encoding='utf-8') as wfile: ? ? ? ? ? ? ? ? ? ? d={} ? ? ? ? ? ? ? ? ? ? for item in student_old: ? ? ? ? ? ? ? ? ? ? ? ? d = dict(eval(item)) ? ? ? ? ? ? ? ? ? ? ? ? if d['id']!=student_id: ? ? ? ? ? ? ? ? ? ? ? ? ? ? wfile.write(str(d)+"\n") ? ? ? ? ? ? ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? ? ? ? ? ? ? flag = True ? ? ? ? ? ? ? ? ? ? if flag: ? ? ? ? ? ? ? ? ? ? ? ? print(f"{student_id}已經(jīng)被刪除!") ? ? ? ? ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? ? ? ? ? print(f"{student_id}沒有找到!") ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? print("無(wú)學(xué)生信息!") ? ? ? ? ? ? ? ? break ? ? ? ? ? ? show() ? ? ? ? ? ? answer = input("是否繼續(xù)刪除?y/n") ? ? ? ? ? ? if answer == 'y': ? ? ? ? ? ? ? ? continue ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? break ? ? ? ? else: ? ? ? ? ? ? print("請(qǐng)輸入要?jiǎng)h除的ID:") ? ? ? ? ? ? continue # 修改 ? ? ? def modify(): ? ? while True: ? ? ? ? student_id = input("請(qǐng)輸入要修改的學(xué)生ID:") ? ? ? ? if student_id: ? ? ? ? ? ? if os.path.exists(filename): ? ? ? ? ? ? ? ? with open(filename,'r',encoding='utf-8') as file: ? ? ? ? ? ? ? ? ? ? student_old = file.readlines() ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? student_old=[] ? ? ? ? ? ? if student_old: ? ? ? ? ? ? ? ? with open(filename,'w',encoding='utf-8') as wfile: ? ? ? ? ? ? ? ? ? ? d = {} ? ? ? ? ? ? ? ? ? ? for item in student_old: ? ? ? ? ? ? ? ? ? ? ? ? d = dict(eval(item)) ? ? ? ? ? ? ? ? ? ? ? ? if d['id'] == student_id: ? ? ? ? ? ? ? ? ? ? ? ? ? ? answer = input('已經(jīng)找到該學(xué)生信息,是否修改:y/n?') ? ? ? ? ? ? ? ? ? ? ? ? ? ? flag = False ? ? ? ? ? ? ? ? ? ? ? ? ? ? if answer: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? d['name']=input("姓名:") ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? d['english']=int(input("english:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? d['python']=int(input("python:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? d['java']=int(input("java:")) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? wfile.write(str(d)+"\n") ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? flag = True ? ? ? ? ? ? ? ? ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? wfile.write(str(d)+"\n") ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break ? ? ? ? ? ? ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? ? ? ? ? ? ? wfile.write(str(d)+"\n") ? ? ? ? ? ? ? ? ? ? if flag: ? ? ? ? ? ? ? ? ? ? ? ? print("修改成功!") ? ? ? ? ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? ? ? ? ? print("修改失??!") ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? print("無(wú)學(xué)生信息,請(qǐng)?zhí)砑?) ? ? ? ? ? ? answer = input("請(qǐng)問是否繼續(xù)修改?y/n") ? ? ? ? ? ? if answer == "y": ? ? ? ? ? ? ? ? continue ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? break ? ? ? ? else: ? ? ? ? ? ? print("輸入錯(cuò)誤!") # 排序 ? ? ? ? ?? def sort(): ? ? while True: ? ? ? ? if os.path.exists(filename): ? ? ? ? ? ? with open(filename,'r',encoding='utf-8') as file: ? ? ? ? ? ? ? ? student_old = file.readlines() ? ? ? ? ? ? student_new = [] ? ? ? ? ? ? d={} ? ? ? ? ? ? for item in student_old: ? ? ? ? ? ? ? ? d=dict(eval(item)) ? ? ? ? ? ? ? ? student_new.append(d) ? ? ? ? ? ? asc_and_desc = int(input("怎么排序:0 升序 ?1 降序:")) ? ? ? ? ? ? choice = int(input("按照什么排序:1 english ?2 python ?3 java ?0 總成績(jī):")) ? ? ? ? ? ? if choice == 1: ? ? ? ? ? ? ? ? student_new.sort(key=lambda x:int(x['english']),reverse=asc_and_desc) ? ? ? ? ? ? elif choice == 2: ? ? ? ? ? ? ? ? student_new.sort(key=lambda x:int(x['python']),reverse=asc_and_desc) ? ? ? ? ? ? elif choice == 3: ? ? ? ? ? ? ? ? ? student_new.sort(key=lambda x:int(x['java']),reverse=asc_and_desc) ? ? ? ? ? ? elif choice == 0: ? ? ? ? ? ? ? ? student_new.sort(key=lambda x:int(x['english'])+int(x['python'])+int(x['java']),reverse=asc_and_desc) ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? print("輸入有誤") ? ? ? ? ? ? ? ? sort() ? ? ? ? else: ? ? ? ? ? ? print("無(wú)學(xué)生信息") ? ? ? ? format_title = '{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}' ? ? ? ? print(format_title.format('ID','姓名','英語(yǔ)成績(jī)','python成績(jī)','java成績(jī)','總成績(jī)')) ? ? ? ? format_data = '{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}' ? ? ? ? for dic in student_new: ? ? ? ? ? ? print(format_data.format(dic.get('id'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('name'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('english'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('python'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('java'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int(dic.get('english'))+int(dic.get('python'))+int(dic.get('java')), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? )) ? ? ? ? answer = input("請(qǐng)問是否繼續(xù)排序?y/n") ? ? ? ? if answer == "y": ? ? ? ? ? ? continue ? ? ? ? else: ? ? ? ? ? ? break # 總?cè)藬?shù) def total(): ? ? if os.path.exists(filename): ? ? ? ? with open(filename,'r',encoding='utf-8') as file: ? ? ? ? ? ? student_old = file.readlines() ? ? ? ? print('一共有',len(student_old),'名學(xué)生!') ? ? else: ? ? ? ? print("無(wú)人員資料") ? ? import msvcrt ? ? msvcrt.getch() # 展示 def show(): ? ? if os.path.exists(filename): ? ? ? ? with open(filename,'r',encoding='utf-8') as file: ? ? ? ? ? ? student_old = file.readlines() ? ? ? ? d = {} ? ? ? ? students = [] ? ? ? ? for item in student_old: ? ? ? ? ? ? d = dict(eval(item)) ? ? ? ? ? ? students.append(d) ? ? else: ? ? ? ? print("沒有信息!") ? ? if len(students): ? ? ? ? format_title = '{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}' ? ? ? ? print(format_title.format('ID','姓名','英語(yǔ)成績(jī)','python成績(jī)','java成績(jī)','總成績(jī)')) ? ? ? ? format_data = '{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}' ? ? ? ? for dic in students: ? ? ? ? ? ? print(format_data.format(dic.get('id'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('name'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('english'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('python'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dic.get('java'), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int(dic.get('english'))+int(dic.get('python'))+int(dic.get('java')), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? )) ? ? else: ? ? ? ? print("無(wú)人員信息!") ? ? import msvcrt ? ? msvcrt.getch() if __name__ == '__main__': ? ? main()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 使用Python實(shí)現(xiàn)簡(jiǎn)單的學(xué)生成績(jī)管理系統(tǒng)
- python mysql實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)
- python實(shí)現(xiàn)簡(jiǎn)易版學(xué)生成績(jī)管理系統(tǒng)
- python創(chuàng)建學(xué)生成績(jī)管理系統(tǒng)
- Python實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)
- Python學(xué)生成績(jī)管理系統(tǒng)簡(jiǎn)潔版
- python超詳細(xì)實(shí)現(xiàn)完整學(xué)生成績(jī)管理系統(tǒng)
相關(guān)文章
Python實(shí)現(xiàn)斐波那契數(shù)列的示例代碼
斐波那契數(shù)列是一種經(jīng)典的數(shù)學(xué)問題,在計(jì)算機(jī)科學(xué)和編程中經(jīng)常被用來(lái)演示算法和遞歸的概念,本文將詳細(xì)介紹斐波那契數(shù)列的定義、計(jì)算方法以及如何在Python中實(shí)現(xiàn)它,需要的可以參考下2024-01-01解讀pandas交叉表與透視表pd.crosstab()和pd.pivot_table()函數(shù)
這篇文章主要介紹了pandas交叉表與透視表pd.crosstab()和pd.pivot_table()函數(shù)的用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09python argparse傳入布爾參數(shù)false不生效的解決
這篇文章主要介紹了python argparse傳入布爾參數(shù)false不生效的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-04-04window7下的python2.7版本和python3.5版本的opencv-python安裝過程
這篇文章主要介紹了window7下的python2.7版本和python3.5版本的opencv-python安裝過程,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10matplotlib grid()設(shè)置網(wǎng)格線外觀的實(shí)現(xiàn)
這篇文章主要介紹了matplotlib grid()設(shè)置網(wǎng)格線外觀的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02Python django搭建layui提交表單,表格,圖標(biāo)的實(shí)例
今天小編就為大家分享一篇Python django搭建layui提交表單,表格,圖標(biāo)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2019-11-11Python Matplotlib庫(kù)實(shí)現(xiàn)畫局部圖
這篇文章主要為大家詳細(xì)介紹了Python Matplotlib庫(kù)實(shí)現(xiàn)畫局部圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11