最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實(shí)現(xiàn)簡(jiǎn)易的學(xué)生信息管理系統(tǒng)

 更新時(shí)間:2022年05月16日 15:18:58   作者:長(zhǎng)得丑就要多讀書(shū)  
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)簡(jiǎn)易的學(xué)生信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python實(shí)現(xiàn)簡(jiǎn)易學(xué)生信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

一、系統(tǒng)功能

1.錄入學(xué)生信息

2.查找學(xué)生信息

3.修改學(xué)生信息

4.刪除學(xué)生信息

5.成績(jī)排序

6.統(tǒng)計(jì)學(xué)生總?cè)藬?shù)

7.顯示所有學(xué)生信息

0.退出系統(tǒng)

二、系統(tǒng)開(kāi)發(fā)環(huán)境

1.操作系統(tǒng):win7

2.開(kāi)發(fā)工具:PyCharm

3.Python內(nèi)置模塊:os,re

三、實(shí)現(xiàn)代碼

import os
filename='students.txt'
def main():
? ? while True:
? ? ? ? menum()
? ? ? ? choice=int(input('請(qǐng)選擇功能:'))
? ? ? ? if choice in [0,1,2,3,4,5,6,7]:
? ? ? ? ? ? if choice==0:
? ? ? ? ? ? ? ? answer=input('您確定要退出系統(tǒng)嗎?(y/n)')
? ? ? ? ? ? ? ? if answer=='y' or answer=='Y':
? ? ? ? ? ? ? ? ? ? print('感謝您的使用!')
? ? ? ? ? ? ? ? ? ? break #退出while循環(huán)并退出系統(tǒng)
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? continue
? ? ? ? ? ? elif choice == 1:
? ? ? ? ? ? ? ? insert() #錄入學(xué)生信息
? ? ? ? ? ? elif choice == 2:
? ? ? ? ? ? ? ? search() #查找學(xué)生信息
? ? ? ? ? ? elif choice == 3:
? ? ? ? ? ? ? ? delete() #刪除學(xué)生信息
? ? ? ? ? ? elif choice == 4:
? ? ? ? ? ? ? ? modify() #修改學(xué)生信息
? ? ? ? ? ? elif choice == 5:
? ? ? ? ? ? ? ? sort() #成績(jī)排序
? ? ? ? ? ? elif choice == 6:
? ? ? ? ? ? ? ? total() #統(tǒng)計(jì)學(xué)生總?cè)藬?shù)
? ? ? ? ? ? elif choice == 7:
? ? ? ? ? ? ? ? show() #顯示所有學(xué)生信息
?
def insert():
? ? student_list=[] #用于存儲(chǔ)學(xué)生信息,列表每個(gè)元素是字典。
? ? while True:
? ? ? ? id=input('請(qǐng)輸入學(xué)生ID:')
? ? ? ? if not id:
? ? ? ? ? ? break
? ? ? ? name=input('請(qǐng)輸入學(xué)生姓名:')
? ? ? ? if not name:
? ? ? ? ? ? break
? ? ? ? try:
? ? ? ? ? ? Englist=int(input('請(qǐng)輸入英語(yǔ)成績(jī):'))
? ? ? ? ? ? Python=int(input('請(qǐng)輸入Python成績(jī):'))
? ? ? ? ? ? Java=int(input('請(qǐng)輸入Java成績(jī):'))
? ? ? ? except:
? ? ? ? ? ? print('輸入無(wú)效,不是整數(shù)類型,請(qǐng)重新輸入!')
? ? ? ? ? ? continue
? ? ? ? #將錄入的學(xué)生信息保存到字典中
? ? ? ? student={'id':id,'name':name,'English':Englist,'Python':Python,'Java':Java}
? ? ? ? #將學(xué)生信息添加到列表中
? ? ? ? student_list.append(student)
? ? ? ? answer=input('是否繼續(xù)添加?(y/n)')
? ? ? ? if answer=='y' or answer=='Y':
? ? ? ? ? ? continue
? ? ? ? else:
? ? ? ? ? ? break
?
? ? #將學(xué)生信息保存在文件中
? ? save(student_list)
? ? print('學(xué)生信息錄入完畢!')
? ? pass
?
def search():
? ? student_query=[] #用列表存儲(chǔ),防止有同名學(xué)生。
? ? while True:
? ? ? ? id=''
? ? ? ? name=''
? ? ? ? if os.path.exists(filename):
? ? ? ? ? ? mode=input('按ID查找請(qǐng)輸入1,按姓名查找請(qǐng)輸入2:')
? ? ? ? ? ? if mode == '1':
? ? ? ? ? ? ? ? id=input('請(qǐng)輸入要查找的學(xué)生ID:')
? ? ? ? ? ? elif mode == '2':
? ? ? ? ? ? ? ? name=input('請(qǐng)輸入要查找的學(xué)生姓名:')
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? print('您的輸入有誤,請(qǐng)重新輸入!')
? ? ? ? ? ? ? ? search()
? ? ? ? ? ? with open(filename,'r',encoding='utf-8') as rfile:
? ? ? ? ? ? ? ? student=rfile.readlines()
? ? ? ? ? ? ? ? for item in student:
? ? ? ? ? ? ? ? ? ? d=dict(eval(item))
? ? ? ? ? ? ? ? ? ? if id!='':
? ? ? ? ? ? ? ? ? ? ? ? if d['id']==id:
? ? ? ? ? ? ? ? ? ? ? ? ? ? student_query.append(d)
? ? ? ? ? ? ? ? ? ? elif name!='':
? ? ? ? ? ? ? ? ? ? ? ? if d['name']==name:
? ? ? ? ? ? ? ? ? ? ? ? ? ? student_query.append(d)
? ? ? ? ? ? #顯示查詢結(jié)果
? ? ? ? ? ? show_student(student_query)
? ? ? ? ? ? student_query.clear() #清空列表
? ? ? ? ? ? answer=input('是否要繼續(xù)查詢?(y/n)')
? ? ? ? ? ? if answer=='y' or answer=='Y':
? ? ? ? ? ? ? ? continue
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? break
? ? ? ? else:
? ? ? ? ? ? print('暫未保存學(xué)生信息。')
? ? ? ? ? ? return
? ? pass
?
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() #讀取所有學(xué)生信息并保存在列表中
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? student_old=[]
? ? ? ? ? ? flag=False #用于標(biāo)記是否刪除
? ? ? ? ? ? if student_old:
? ? ? ? ? ? ? ? with open(filename,'w',encoding='utf-8') as wfile:
? ? ? ? ? ? ? ? ? ? d={}
? ? ? ? ? ? ? ? ? ? for item in student_old: #遍歷學(xué)生信息列表
? ? ? ? ? ? ? ? ? ? ? ? d=dict(eval(item)) #將字符串轉(zhuǎn)成字典
? ? ? ? ? ? ? ? ? ? ? ? if d['id']!=student_id:
? ? ? ? ? ? ? ? ? ? ? ? ? ? wfile.write(str(d)+'\n')
? ? ? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? ? ? flag=True
? ? ? ? ? ? ? ? ? ? if flag:
? ? ? ? ? ? ? ? ? ? ? ? print(f'id為{student_id}的學(xué)生信息已被刪除')
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? print(f'沒(méi)有找到ID為{student_id}的學(xué)生信息')
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? print('無(wú)此學(xué)生信息')
? ? ? ? ? ? ? ? break
? ? ? ? ? ? show() #刪完之后重新顯示所有學(xué)生信息
? ? ? ? ? ? answer=input('是否繼續(xù)刪除?(y/n)')
? ? ? ? ? ? if answer=='y' or answer=='Y':
? ? ? ? ? ? ? ? continue
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? break
? ? pass
?
def modify():
? ? show()
? ? if os.path.exists(filename): #判斷文件是否存在
? ? ? ? with open(filename,'r',encoding='utf-8') as rfile:
? ? ? ? ? ? student_old=rfile.readlines()
? ? else:
? ? ? ? return #結(jié)束函數(shù)
? ? student_id=input('請(qǐng)輸入要修改信息的學(xué)生ID:')
? ? with open(filename,'w',encoding='utf-8') as wfile:
? ? ? ? for item in student_old:
? ? ? ? ? ? d=dict(eval(item))
? ? ? ? ? ? if d['id']==student_id:
? ? ? ? ? ? ? ? print('找到此學(xué)生信息,可以修改。')
? ? ? ? ? ? ? ? while True:
? ? ? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? ? ? d['name']=input('請(qǐng)輸入學(xué)生姓名:')
? ? ? ? ? ? ? ? ? ? ? ? d['English']=input('請(qǐng)輸入English成績(jī):')
? ? ? ? ? ? ? ? ? ? ? ? d['Python']=input('請(qǐng)輸入Python成績(jī):')
? ? ? ? ? ? ? ? ? ? ? ? d['Java']=input('請(qǐng)輸入Java成績(jī):')
? ? ? ? ? ? ? ? ? ? except:
? ? ? ? ? ? ? ? ? ? ? ? print('您的輸入有誤請(qǐng)重新輸入!')
? ? ? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? ? ? break
? ? ? ? ? ? ? ? wfile.write(str(d)+'\n')
? ? ? ? ? ? ? ? print('修改成功!')
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? wfile.write(str(d)+'\n')
? ? ? ? answer=input('是否繼續(xù)修改其他學(xué)生信息?(y/n)')
? ? ? ? if answer=='y':
? ? ? ? ? ? modify()
? ? pass
?
def sort():
? ? show()
? ? if os.path.exists(filename):
? ? ? ? with open(filename,'r',encoding='utf-8') as rfile:
? ? ? ? ? ? student_list=rfile.readlines()
? ? ? ? student_new=[]
? ? ? ? for item in student_list:
? ? ? ? ? ? d=dict(eval(item))
? ? ? ? ? ? student_new.append(d)
? ? else:
? ? ? ? return
? ? asc_or_desc=input('請(qǐng)選擇(0:升序,1:降序):')
? ? if asc_or_desc=='0':
? ? ? ? asc_or_desc_bool=False
? ? elif asc_or_desc=='1':
? ? ? ? asc_or_desc_bool=True
? ? else:
? ? ? ? print('您的輸入有誤,請(qǐng)重新輸入!')
? ? ? ? sort()
? ? mode=input('請(qǐng)選擇排序方式(0:按總成績(jī)排序,1:按English成績(jī)排序,2:按Python成績(jī)排序,3:按Java成績(jī)排序)')
? ? if mode=='0':
? ? ? ? student_new.sort(key=lambda x: int(x['English'])+int(x['Python'])+int(x['Java']), reverse=asc_or_desc_bool)
? ? elif mode=='1':
? ? ? ? student_new.sort(key=lambda x:int(x['English']),reverse=asc_or_desc_bool)
? ? elif mode=='2':
? ? ? ? student_new.sort(key=lambda x: int(x['Python']), reverse=asc_or_desc_bool)
? ? elif mode=='3':
? ? ? ? student_new.sort(key=lambda x: int(x['Java']), reverse=asc_or_desc_bool)
? ? else:
? ? ? ? print('您的輸入有誤,請(qǐng)重新輸入!')
? ? ? ? sort()
? ? show_student(student_new)
? ? pass
?
def total():
? ? if os.path.exists(filename):
? ? ? ? with open(filename,'r',encoding='utf-8') as rfile:
? ? ? ? ? ? students=rfile.readlines()
? ? ? ? ? ? if students:
? ? ? ? ? ? ? ? print(f'一共有{len(students)}名學(xué)生')
? ? ? ? ? ? else:
? ? ? ? ? ? ? ? print('還沒(méi)有錄入學(xué)生信息!')
? ? else:
? ? ? ? print('暫未保存學(xué)生信息......')
? ? pass
?
def show():
? ? student_lst=[]
? ? if os.path.exists(filename):
? ? ? ? with open(filename,'r',encoding='utf-8') as rfile:
? ? ? ? ? ? students=rfile.readlines()
? ? ? ? ? ? for item in students:
? ? ? ? ? ? ? ? student_lst.append(eval(item))
? ? ? ? ? ? if student_lst:
? ? ? ? ? ? ? ? show_student(student_lst)
? ? else:
? ? ? ? print('暫未保存過(guò)數(shù)據(jù)!')
? ? pass
?
def save(stu_list):
? ? try:
? ? ? ? stu_txt=open(filename,'a',encoding='utf=8')
? ? except:
? ? ? ? stu_txt=open(filename,'w',encoding='utf-8')
? ? for item in stu_list:
? ? ? ? stu_txt.write(str(item)+'\n')
? ? stu_txt.close()
?
def show_student(lst):
? ? if len(lst)==0:
? ? ? ? print('沒(méi)有查到學(xué)生信息,無(wú)數(shù)據(jù)顯示!')
? ? ? ? return
? ? #定義標(biāo)題顯示格式
? ? format_title='{:^6}\t{:^12}\t{:^10}\t{:^10}\t{:^10}\t{:^8}'
? ? print(format_title.format('ID','姓名','English成績(jī)','Python成績(jī)','Java成績(jī)','總成績(jī)'))
? ? #定義內(nèi)容顯示格式
? ? format_data='{:^6}\t{:^12}\t{:^10}\t{:^18}\t{:^14}\t{:^8}'
? ? for item in lst:
? ? ? ? print(format_data.format(item.get('id'),item.get('name'),item.get('English'),item.get('Python'),item.get('Java'),str(int(item.get('English'))+int(item.get('Python'))+int(item.get('Java')))))
? ? pass
?
def menum():
? ? print('-------------------學(xué)生信息管理系統(tǒng)--------------------')
? ? print('-----------------------功能菜單------------------------')
? ? print(' ? ? ? ? ? ? ? ? ? ?1.錄入學(xué)生信息')
? ? print(' ? ? ? ? ? ? ? ? ? ?2.查找學(xué)生信息')
? ? print(' ? ? ? ? ? ? ? ? ? ?3.刪除學(xué)生信息')
? ? print(' ? ? ? ? ? ? ? ? ? ?4.修改學(xué)生信息')
? ? print(' ? ? ? ? ? ? ? ? ? ?5.成績(jī)排序')
? ? print(' ? ? ? ? ? ? ? ? ? ?6.統(tǒng)計(jì)學(xué)生總?cè)藬?shù)')
? ? print(' ? ? ? ? ? ? ? ? ? ?7.顯示所有學(xué)生信息')
? ? print(' ? ? ? ? ? ? ? ? ? ?0.退出系統(tǒng)')
? ? print('------------------------------------------------------')
?
main()

四、項(xiàng)目打包并生成.exe可執(zhí)行文件

1.安裝第三方模塊,打開(kāi)dos窗口,輸入:pip install PyInstaller并回車,

2.輸入:pyinstaller -F 程序文件具體位置,

3.回車后即可在輸出內(nèi)容的倒數(shù)第二行看到.exe文件的位置。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python實(shí)現(xiàn)json轉(zhuǎn)yolo格式

    python實(shí)現(xiàn)json轉(zhuǎn)yolo格式

    在目標(biāo)檢測(cè)數(shù)據(jù)集處理中,我們經(jīng)常會(huì)遇到標(biāo)簽之間不同格式的轉(zhuǎn)化,本文主要介紹了python實(shí)現(xiàn)json轉(zhuǎn)yolo格式,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-12-12
  • Python異步與定時(shí)任務(wù)提高程序并發(fā)性和定時(shí)執(zhí)行效率

    Python異步與定時(shí)任務(wù)提高程序并發(fā)性和定時(shí)執(zhí)行效率

    Python異步與定時(shí)任務(wù)是Python編程中常用的兩種技術(shù),異步任務(wù)可用于高效處理I/O密集型任務(wù),提高程序并發(fā)性;定時(shí)任務(wù)可用于定時(shí)執(zhí)行計(jì)劃任務(wù),提高程序的執(zhí)行效率。這兩種技術(shù)的應(yīng)用有助于提升Python程序的性能和效率
    2023-05-05
  • Python實(shí)現(xiàn)獲取當(dāng)前目錄下文件名代碼詳解

    Python實(shí)現(xiàn)獲取當(dāng)前目錄下文件名代碼詳解

    這篇文章主要介紹了Python實(shí)現(xiàn)獲取當(dāng)前目錄下文件名,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • Python生成指定數(shù)量的優(yōu)惠碼實(shí)操內(nèi)容

    Python生成指定數(shù)量的優(yōu)惠碼實(shí)操內(nèi)容

    在本篇文章里小編給大家整理了關(guān)于Python生成指定數(shù)量的優(yōu)惠碼的實(shí)例內(nèi)容以及相關(guān)代碼,有需要的朋友們學(xué)習(xí)下。
    2019-06-06
  • Python+numpy實(shí)現(xiàn)矩陣的行列擴(kuò)展方式

    Python+numpy實(shí)現(xiàn)矩陣的行列擴(kuò)展方式

    今天小編就為大家分享一篇Python+numpy實(shí)現(xiàn)矩陣的行列擴(kuò)展方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-11-11
  • pandas取出重復(fù)數(shù)據(jù)的方法

    pandas取出重復(fù)數(shù)據(jù)的方法

    今天小編就為大家分享一篇pandas取出重復(fù)數(shù)據(jù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-07-07
  • python中的deque基本用法詳解

    python中的deque基本用法詳解

    Python?中的?deque是一個(gè)低級(jí)別的、高度優(yōu)化的雙端隊(duì)列,對(duì)于實(shí)現(xiàn)優(yōu)雅、高效的Pythonic隊(duì)列和堆棧很有用,這篇文章主要介紹了python中的deque基本用法的相關(guān)資料,需要的朋友可以參考下
    2017-11-11
  • python實(shí)現(xiàn)Android與windows局域網(wǎng)文件夾同步

    python實(shí)現(xiàn)Android與windows局域網(wǎng)文件夾同步

    這篇文章主要給大家詳細(xì)介紹了python實(shí)現(xiàn)Android與windows局域網(wǎng)文件夾同步,文中有詳細(xì)的代碼示例和圖文介紹,具有一定的參考價(jià)值,需要的朋友可以參考下
    2023-09-09
  • 詳解Python中最常用的10個(gè)內(nèi)置函數(shù)

    詳解Python中最常用的10個(gè)內(nèi)置函數(shù)

    Python作為一種多用途編程語(yǔ)言,擁有豐富的內(nèi)置函數(shù)庫(kù),這些函數(shù)可以極大地提高開(kāi)發(fā)效率,本文將介紹Python中最常用的10個(gè)內(nèi)置函數(shù),我們將深入了解每個(gè)函數(shù),并提供示例代碼以幫助您更好地理解它們,需要的朋友可以參考下
    2023-11-11
  • python實(shí)現(xiàn)數(shù)字炸彈游戲程序

    python實(shí)現(xiàn)數(shù)字炸彈游戲程序

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)數(shù)字炸彈游戲程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-07-07

最新評(píng)論

平山县| 宜昌市| 汉沽区| 瑞昌市| 仁布县| 叙永县| 新平| 绍兴市| 通榆县| 嵊泗县| 昔阳县| 化隆| 曲松县| 治县。| 仙居县| 台南县| 武宣县| 利辛县| 滕州市| 廊坊市| 汕头市| 喀喇| 阿瓦提县| 涪陵区| 客服| 淮滨县| 东乡县| 沙坪坝区| 阳新县| 永修县| 遂宁市| 宿迁市| 涡阳县| 庆城县| 金华市| 宣恩县| 韶山市| 城市| 荔波县| 临海市| 文安县|