主頁 > 後端開發 > python學習-學生資訊管理系統并打包exe

python學習-學生資訊管理系統并打包exe

2023-04-23 07:31:51 後端開發

在B站自學Python
站主:Python_子木
授課:楊淑娟
平臺: 馬士兵教育
python: 3.9.9

python打包exe檔案

#安裝PyInstaller
pip install PyInstaller
#-F打包exe檔案,stusystem\stusystem.py到py的路徑,可以是絕對路徑,可以是相對路徑
pyinstaller -F stusystem\stusystem.py

學生資訊管理系統具體代碼如下

import os.path
filename='student.txt'
def main():
    while True:
        menu()
        choice = int(input('請選擇'))
        if choice in range(8):
            if choice==0:
                answer=input('您確定要退出系統嗎?y/n')
                if answer.lower()=='y':
                    print('謝謝您的使用!')
                    break #退出系統
                else:
                    continue
            if choice==1:
                insert()
            if choice==2:
                search()
            if choice==3:
                delete()
            if choice==4:
                modify()
            if choice==5:
                sort()
            if choice==6:
                total()
            if choice==7:
                show()
        else:
            print('無此功能,請按選單重新選擇')
def menu():
    print('=========================學生資訊管理系統============================')
    print('-----------------------------功能選單------------------------------')
    print('\t\t\t\t\t\t1.錄入學生資訊')
    print('\t\t\t\t\t\t2.查找學生資訊')
    print('\t\t\t\t\t\t3.洗掉學生資訊')
    print('\t\t\t\t\t\t4.修改學生資訊')
    print('\t\t\t\t\t\t5.排序')
    print('\t\t\t\t\t\t6.統計學生總人數')
    print('\t\t\t\t\t\t7.顯示所有學生資訊')
    print('\t\t\t\t\t\t0.退出')
    print('------------------------------------------------------------------')

def insert():
    student_list=[]
    while True:
        id=input('請輸入ID(如1001):')
        if not id:
            break
        name=input('請輸入姓名:')
        if not name:
            break
        try:
            english=int(input('請輸入英語成績:'))
            python=int(input('請輸入Python成績:'))
            java=int(input('請輸入Java成績:'))
        except:
            print('輸入無效,不是整數型別,請重新輸入')
            continue
        #將錄入的學生保存到字典中
        student={'id':id,'name':name,'english':english,'python':python,'java':java}
        #將學生資訊添加到串列中
        student_list.append(student)
        answer=input('是否繼續添加?y/n')
        if answer.lower()=='y':
            continue
        else:
            break

    #呼叫save()函式
    save(student_list)
    print('學生資訊錄入完畢!!!')

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():
    student_query=[]
    while True:
        id=''
        name=''
        if os.path.exists(filename):
            mode=input('按ID查找請輸入1,按姓名查找請輸入2:')
            if mode=='1':
                id=input('請輸入學生ID:')
            elif mode=='2':
                name=input('請輸入學生姓名:')
            else:
                print('您輸入有誤,請重新輸入')
                continue
            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)
            #顯示查詢結果
            show_student(student_query)
            #清空串列
            student_query.clear()
            answer=input('是否要繼續查詢?y/n\n')
            if answer.lower()=='y':
                continue
            else:
                break
        else:
            print('暫未保存學生資訊')
            return
def show_student(lst):
    if len(lst)==0:
        print('沒有查詢到學生資訊,無資料顯示!!!')
        return
    #定義標題顯示格式
    format_title='{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}\t'
    print(format_title.format('ID','姓名','英語成績','Python成績','Java成績','總成績'))
    #定義內容顯示格式
    format_data='https://www.cnblogs.com/chenlei53/archive/2023/04/22/{:^6}/t{:^12}/t{:^8}/t{:^8}/t{:^8}/t{:^8}/t'
    for item in lst:
        print(format_data.format(item.get('id'),
                                 item.get('name'),
                                 item.get('english'),
                                 item.get('python'),
                                 item.get('java'),
                                 int(item.get('english'))+int(item.get('python'))+int(item.get('java'))
                                 ))


def delete():
    while True:
        student_id=input('請輸入要洗掉的學生的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'id為{student_id}的學生資訊已被洗掉')
                    else:
                        print(f'沒有找到ID為{student_id}的學生資訊')
            else:
                print('無學生資訊')
                break
            show() #洗掉之后要重新顯示所有學生資訊
            answer=input('是否繼續洗掉?y/n')
            if answer.lower()=='y':
                continue
            else:
                break

def modify():
    show()
    if os.path.exists(filename):
        with open(filename,'r',encoding='utf-8') as rfile:
            student_old=rfile.readlines()
    else:
        return
    student_id=input('請輸入要修改的學員的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('找到學生資訊,可以修改他的相關資訊了!')
                while True:
                    try:
                        d['name']=input('請輸入姓名:')
                        d['english']=input('請輸入英語成績:')
                        d['python']=input('請輸入python成績:')
                        d['java']=input('請輸入java成績:')
                    except:
                        print('您的輸入有誤,請重新輸入!!!')
                    else:
                        break
                wfile.write(str(d)+'\n')
                print('修改成功!')
                show()
            else:
                print(f'未找到ID為{student_id}的學生資訊')
                wfile.write(str(d)+'\n')
        answer=input('是否繼續修改其他學生資訊?y/n\n')
        if answer.lower()=='y':
            modify()

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('請選擇(0.升序,1.降序):')
    if asc_or_desc=='0':
        asc_or_desc_bool=False
    elif asc_or_desc=='1':
        asc_or_desc_bool=True
    else:
        print('您的輸入有誤,請重新輸入')
        sort()
    mode=input('請選擇排序方式(1.按英語成績排序 2.按Python成績排序 3.按Java成績排序 4.按總成績排序)')
    if 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)
    elif mode=='4':
        student_new.sort(key=lambda x:int(x['english'])+int(x['python'])+int(x['java']),reverse=asc_or_desc_bool)
    else:
        print('您的輸入有誤,請重新輸入')
        sort()
    show_student(student_new)
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)}名學生')
            else:
                print('還沒有錄入學生資訊')
    else:
        print('暫未保存資料資訊...')
def show():
    student_list = []
    if os.path.exists(filename):
        # 定義標題顯示格式
        format_title = '{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}\t'
        print(format_title.format('ID', '姓名', '英語成績', 'Python成績', 'Java成績', '總成績'))
        with open(filename,'r',encoding='utf-8') as rfile:
            student = rfile.readlines()
            for item in student:
                d = dict(eval(item))
                student_list.append(d)
        if len(student_list)==0:
            format_nodata = 'https://www.cnblogs.com/chenlei53/archive/2023/04/22/{:^6}'
            print(format_nodata.format('無資料'))
        # 定義內容顯示格式
        format_data = 'https://www.cnblogs.com/chenlei53/archive/2023/04/22/{:^6}/t{:^12}/t{:^8}/t{:^8}/t{:^8}/t{:^8}/t'
        for item in student_list:
            print(format_data.format(item.get('id'),
                                    item.get('name'),
                                    item.get('english'),
                                    item.get('python'),
                                    item.get('java'),
                                    int(item.get('english')) + int(item.get('python')) + int(item.get('java'))
                                    ))
        student_list.clear()
    else:
        print('暫未保存過資料!!!')


if __name__ == '__main__':
    main()

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/550843.html

標籤:其他

上一篇:windows10下golang使用protobuf前奏

下一篇:返回列表

標籤雲
其他(157840) Python(38092) JavaScript(25381) Java(17985) C(15215) 區塊鏈(8256) C#(7972) AI(7469) 爪哇(7425) MySQL(7137) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4557) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2430) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1959) Web開發(1951) HtmlCss(1919) python-3.x(1918) 弹簧靴(1913) C++(1910) xml(1889) PostgreSQL(1872) .NETCore(1854) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • python學習-學生資訊管理系統并打包exe

    在B站自學Python 站主:Python_子木 授課:楊淑娟 平臺: 馬士兵教育 python: 3.9.9 #python打包exe檔案 #安裝PyInstaller pip install PyInstaller #-F打包exe檔案,stusystem\stusystem.py到py的路徑, ......

    uj5u.com 2023-04-23 07:31:51 more
  • windows10下golang使用protobuf前奏

    1.更改代理(方便步驟3) 方法一: go env -w GOPROXY="https://goproxy.cn" 方法二:(非永久性,該方法對我有效) $env:GOPROXY="https://goproxy.cn" 注: http://mirrors.aliyun.com/goproxy/ 阿 ......

    uj5u.com 2023-04-23 07:31:46 more
  • 影像梯度

    影像梯度影像梯度計算的是影像變化的速度 對于影像的邊緣部分,其灰度值變化較大,梯度值也較大相反,對于影像中比較平滑的部分,其灰度值變化較小,相應的梯度值也較小。影像梯度計算需要求導數,但是影像梯度一般通過計算像素值的差來得到梯度的近似值(近似導數值)。(差分,離散) Sobel算子 1 #Sobel ......

    uj5u.com 2023-04-23 07:31:41 more
  • Rust編程語言入門之模式匹配

    模式匹配 模式 模式是Rust中的一種特殊語法,用于匹配復雜和簡單型別的結構 將模式與匹配運算式和其他構造結合使用,可以更好地控制程式的控制流 模式由以下元素(的一些組合)組成: 字面值 解構的陣列、enum、struct 和 tuple 變數 通配符 占位符 想要使用模式,需要將其與某個值進行比較 ......

    uj5u.com 2023-04-23 07:31:37 more
  • 影像金字塔

    影像金字塔 簡單來說就是 自下而上影像一步一步縮小 1 高斯金字塔(涉及高斯分布) 向下采樣(縮小,對金字塔來說是自下向上) 第一步: 高斯濾波去噪 第二部:將偶數行和列去掉 向上采樣(放大,對金字塔來說是自上向下) 第一步:在每個方向上擴大兩倍,新增的行和列填充0 第二步:利用之前同樣的內核進行卷 ......

    uj5u.com 2023-04-23 07:25:47 more
  • 影像邊緣檢測(Canny)

    Canny檢測的流程 Canny檢測主要是用于邊緣檢測 1)使用高斯濾波器,以平滑影像,濾除噪聲。 2)計算影像中每個像素點的梯度強度和方向。 3)應用非極大值(Non-Maximum Suppression)抑制,以消除邊緣檢測帶來的雜散回應 4)應用雙閾值(Double-Threshold)檢測 ......

    uj5u.com 2023-04-23 07:20:41 more
  • python| 關于excel的檔案處理

    創建一個成績單檔案score.xlsx,將平時成績單.xlsx檔案中對應班級作業表中學號和姓名列的內容寫入到score.xlsx中,并添加成績列,每個學生的成績采用隨機生成的一個分數填寫進去,最后統計所有學生的平均成績計算出來后,寫入到score.xlsx的最后一行最后一列之后的單元格中去。預想的步 ......

    uj5u.com 2023-04-23 07:19:54 more
  • java 發送 http 請求練習兩年半(HttpURLConnection)

    1、起一個 springboot 程式做 http 測驗: @GetMapping("/http/get") public ResponseEntity<String> testHttpGet(@RequestParam("param") String param) { System.out.pri ......

    uj5u.com 2023-04-22 07:35:28 more
  • Django筆記二十七之資料庫函式之文本函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十七之資料庫函式之文本函式 這篇筆記將介紹如何使用資料庫函式里的文本函式。 顧名思義,文本函式,就是針對文本欄位進行操作的函式,如下是目錄匯總: Concat() —— 合并 Left() —— 從左邊開始截取 Length() —— ......

    uj5u.com 2023-04-22 07:35:22 more
  • Rust中的Copy和Clone

    1.Copy和Clone Rust中的Copy和Clonetrait都允許創建型別實體的副本。它們都提供了一種復制型別實體的方法,但它們之間存在一些重要的區別。了解這些區別有助更好地使用這兩個特征。 2. Copytrait Copytrait允許按位復制型別的實體。這意味著當您將一個變數賦值給另一 ......

    uj5u.com 2023-04-22 07:35:17 more