溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)

發(fā)布時間:2022-04-26 15:57:57 來源:億速云 閱讀:139 作者:iii 欄目:開發(fā)技術(shù)

這篇“python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)”文章的知識點大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)”文章吧。

學(xué)生信息系統(tǒng)

提示:python編寫的學(xué)生成績管理系統(tǒng),包括8個功能和打包教程

一、功能界面 

def menum():
    print('==================student_manger=================')
    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)計學(xué)生總?cè)藬?shù)')
    print('\t\t7.顯示所有學(xué)生信息')
    print('\t\t8.顯示功能介紹按鈕')
    print('\t\t0.退出')
    print('================================================')

二 、主函數(shù) 

def main():
    menum()
    while True:
        try:
            choice = int(input('請選擇你想進(jìn)行的操作: '))
        except ValueError:
            print('輸入的數(shù)據(jù)存在錯誤,只能輸入0到7的整數(shù)!')
            try:
                choice = int(input('請重新輸入: '))
            except ValueError:
                print('重復(fù)輸入錯誤,退出系統(tǒng)!')
                break
        if choice in [0, 1, 2, 3, 4, 5, 6, 7, 8]:
            if choice == 0:
                answer = input('你確定要退出系統(tǒng)嗎?(Y/N): ')
                if answer == 'Y' or answer == 'y':
                    print('謝謝使用!')
                    break
                elif answer == 'N' or answer == 'n':
                    print('即將返回上一步操作!')
                    continue
                else:
                    input('輸入錯誤,即將返回主界面!')
                    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()
            elif choice == 7:
                show()
            else:
                menum()
        else:
            print('你選擇的操作無效,請重新輸入!:')

三 、學(xué)生信息錄入功能

邏輯結(jié)構(gòu)圖

python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)

def insert():
    student_list = []
    id_list = []
    while True:
        id = input('請輸入ID: ')
        if not id:
            break
        name = input('請輸入姓名:')
        if not name:
            break
        try:
            english = float(input('請輸入英語成績:'))
            math = float(input('請輸入數(shù)學(xué)成績:'))
            python = float(input('請輸入Python成績:'))
        except ValueError:
            print('數(shù)據(jù)輸入錯誤!')
            continue
        # 將錄入的學(xué)生信息存放到字典中
        student = {'id': id, 'name': name, 'english': english, 'math': math, 'Python': python}
        # 將每個學(xué)生的信息存放在列表中
        if student['id'] in id_list:                    # student['id'] = value(id)
            print('已存在相同ID:')
            for i in range(len(student_list)):
                if student_list[i][id] == student[id]:  # 輸出重復(fù)id元素
                    print(student_list[i].items())
                    break
            print('請重新錄入!')
        else:
            id_list.append(str(student['id']))
            student_list.append(student)
        # 是否繼續(xù)添加學(xué)生信息
        answer = input('是否繼續(xù)添加學(xué)生信息?(Y/N): ')
        if answer == 'Y' or answer == 'y':
            continue
        elif answer == 'N' or answer == 'n':
            # 存儲學(xué)生信息
            save(student_list, filename)
            print('學(xué)生信息錄入完畢!')
            break
        else:
            print('輸入錯誤,即將返回主界面!')
            break

四 、學(xué)生信息查找功能

邏輯結(jié)構(gòu)圖

python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)

代碼

def search():
    while True:
        if os.path.exists(filename):
            with open(filename, 'r', encoding = 'utf-8') as s_file:
                student_qurey = s_file.readlines()              # 將學(xué)生信息全部取出
                id_list = []
                name_list = []
                for i in student_qurey:
                    d = dict(eval(i))
                    id_list.append(d['id'])                    # 將所有學(xué)生的id存放在id_list中
                    name_list.append(d['name'])                # 將所有學(xué)生的name存放在id_list中
            try:
                mode = int(input('請選擇查詢模式: 1.按照ID查詢 / 2.按照姓名查詢 '))
            except ValueError:
                print('數(shù)據(jù)類型輸入錯誤!請重新輸入!')
            else:
                if mode == 1:                                  # 按照ID查詢
                    id = input('請輸入學(xué)生id: ')
                    if id in id_list:
                        print('已經(jīng)查找到該名學(xué)生:')
                        print('ID\t\t\t姓名:\t\t英語成績:\t\t數(shù)學(xué)成績:\t\tPython成績:\t\t總成績:')
                        for item in student_qurey:
                            if dict(eval(item))['id'] == id:
                                p = dict(eval(item))
                                print('{0}\t\t{1}\t\t {2}\t\t {3}\t\t   {4}\t\t   {5}'.format(
                                                 p['id'], p['name'], p['english'], p['math'], p['Python'],
                                                 float(p['english'])+float(p['math'])+float(p['Python'])))
                    else:
                        print('查無此人!')
                elif mode == 2:                               # 按照姓名查詢
                    name = input('請輸入學(xué)生姓名: ')
                    if name in name_list:
                        print('已經(jīng)查找到該名學(xué)生:')
                        print('ID\t\t\t姓名:\t\t英語成績:\t\t數(shù)學(xué)成績:\t\tPython成績:\t\t總成績:')
                        for item in student_qurey:
                            if dict(eval(item))['name'] == name:
                                p = dict(eval(item))
                                print('{0}\t\t{1}\t\t {2}\t\t {3}\t\t   {4}\t\t   {5}'.format(
                                    p['id'], p['name'], p['english'], p['math'], p['Python'],
                                    float(p['english']) + float(p['math']) + float(p['Python'])))
                    else:
                        print('查無此人!')
                else:
                    print('輸入錯誤,只能選擇1/2兩種模式!')
                answer = input('是否繼續(xù)查詢? (Y/N)')
                if answer == 'Y' or answer == 'y':
                    continue
                elif answer == 'N' or answer == 'n':
                    print('正在退出查詢..')
                    break
                else:
                    print('輸入錯誤,即將返回主界面!')
                    break
        else:
            print('無學(xué)生信息文件!')
            return

五 、刪除學(xué)生信息

邏輯結(jié)構(gòu)圖

python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)

代碼

def delete():
    while True:
        student_id = input('請輸入想要刪除的學(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                            # 標(biāo)記是否刪除
            if student_old:
                with open(filename, 'w', encoding = 'utf-8') as wfile:
                    for item in student_old:
                        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'沒有找到id為{student_id}的學(xué)生信息!')
            else:
                print('無學(xué)生信息')
                break
            show()                  # 顯示更新后的文件信息
            answer = input('是否繼續(xù)刪除學(xué)生信息?(Y/N): ')
            if answer == 'Y' or answer == 'y':
                continue
            elif answer == 'N' or answer == 'n':
                break
            else:
                print('輸入錯誤,即將返回主界面!')
                break

六 、學(xué)生信息修改功能

邏輯結(jié)構(gòu)圖

python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)

代碼

def modify():
    show()
    if os.path.exists(filename):
        with open(filename, 'r', encoding = 'utf-8') as rfile:
            student_old = rfile.readlines()             # 直接將文本文件的內(nèi)容整行讀取到列表中
    else:
        print('學(xué)生文件信息不存在!')
    student_id = input('請輸入想要修改的學(xué)生的ID: ')
    with open(filename, 'w', encoding = 'utf-8') as just_file:  # 判斷學(xué)生是否在該系統(tǒng)中
        id_list = []
        for i in student_old:
            d = dict(eval(i))
            id_list.append(d['id'])                             # 將所有學(xué)生的id存放在id_list中
        if student_id in id_list:                               # 要修改的學(xué)生存在時
            for item in student_old:
                e = dict(eval(item))
                if e['id'] == student_id:
                    print('已找到該名學(xué)生!')
                    while True:
                        try:
                            e['name'] = input('請輸入姓名: ')
                            e['english'] = input('請輸入英語成績: ')
                            e['math'] = input('請輸入數(shù)學(xué)成績: ')
                            e['Python'] = input('請輸入Python成績: ')
                        except ValueError:
                            print('數(shù)據(jù)類型輸入錯誤!請重新輸入!')
                        else:
                            break  # try...except..else: 輸入為出錯時,執(zhí)行else語句
                    just_file.write(str(e) + '\n')
                    print('修改成功!')
                else:
                    just_file.write(str(e) + '\n')
        else:
            answer1 = input('查無此人!,是否執(zhí)行插入操作?  (Y/N)')
            if answer1 == 'Y' or answer1 == 'y':
                insert()
            else:
                print('結(jié)束當(dāng)前操作')
        answer = input('是否繼續(xù)修改其余學(xué)生信息?(Y/N): ')
        if answer == 'Y' or answer == 'y':
            modify()
        elif answer == 'N' or answer == 'n':
            print('結(jié)束修改,即將返回主界面..')
        else:
            print('輸入錯誤,即將返回主界面!')

七 、學(xué)生成績排序

邏輯結(jié)構(gòu)圖

python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)

代碼

def sort():
    student_new = []
    if os.path.exists(filename):
        with open(filename, 'r', encoding = 'utf-8') as sort_file:
            student_list = sort_file.readlines()                    # 無序的學(xué)生信息列表
        for item in student_list:
            d = dict(eval(item))
            student_new.append(d)                                   # 列表元素轉(zhuǎn)化為字典
        while True:
            try:
                sort_choice = int(input('請選擇排序方式: 0:升序 / 1:降序\t'))
            except ValueError:
                print('輸入的數(shù)據(jù)類型錯誤,請重新輸入')
            else:
                if sort_choice == 0:
                    Flag = False
                    break
                elif sort_choice == 1:
                    Flag = True
                    break
                else:
                    print('輸入錯誤,只能在0/1中選擇!')
                    continue
        while True:
            try:
                asc_choice = int(input('請選擇按照哪一門成績進(jìn)行排序: 英語:0  / 數(shù)學(xué):1  / python:2\t\t'))
            except ValueError:
                print('輸入的數(shù)據(jù)類型錯誤,請重新輸入')
            else:
                if asc_choice == 0:
                    student_new.sort(key = lambda x: int(x['english']), reverse = Flag)     # 根據(jù)列表中的元素進(jìn)行排序
                    show()
                    break
                elif asc_choice == 1:
                    student_new.sort(key = lambda x: int(x['math']), reverse = Flag)
                    show()
                    break
                elif asc_choice == 2:
                    student_new.sort(key = lambda x: int(x['Python']), reverse = Flag)
                    show()
                    break
                elif asc_choice == 3:
                    student_new.sort(key = lambda x: int(x['Python'])+int(x['english'])+int(x['math']), reverse = Flag)
                    show()
                    break
                else:
                    print('輸入錯誤,只能在0/1/2中選擇!')
                    continue
    else:
        print('學(xué)生信息文件不存在!')

八 、 學(xué)生人數(shù)統(tǒng)計

邏輯結(jié)構(gòu)圖

python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)

代碼

def total():
    nums = 0
    if os.path.exists(filename):
        with open(filename, 'r', encoding = 'utf-8') as t_file:
            len_list = t_file.readlines()
        for i in range(len(len_list)):
            if len_list[i] != '':
                nums += 1
        print('當(dāng)前學(xué)生總?cè)藬?shù)為: ', nums)
        print('請選擇你想進(jìn)行的下一步操作: ')
    else:
        print('暫無學(xué)生信息文件')

九 、顯示所有學(xué)生信息

邏輯結(jié)構(gòu)圖

python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)

代碼

def show():
    if os.path.exists(filename):
        with open(filename, 'r', encoding = 'utf-8') as show_file:
            student_list = show_file.readlines()
            if student_list:
                print('----全部學(xué)生信息如下----')
                print('ID\t\t\t姓名:\t\t英語成績:\t\t數(shù)學(xué)成績:\t\tPython成績:\t\t總成績:')
                for item in student_list:
                    p = dict(eval(item))
                    print('{0}\t\t{1}\t\t {2}\t\t {3}\t\t   {4}\t\t   {5}'.format(
                        p['id'], p['name'], p['english'], p['math'], p['Python'],
                        float(p['english']) + float(p['math']) + float(p['Python'])))
            else:
                print('暫無學(xué)生信息!')
    else:
        print('暫無學(xué)生信息!')

程序打包

在 pycharm 終端 或者 python命令界面, 使用:

pip install PyInstaller

下載python打包程序,下載完成后, 執(zhí)行以下操作:

pyinstaller —F F:\xxxx\xxx\xx\x.py

其中:

  • -F 代表將程序打包為單個exe文件,

  • F:\xxx\xxx\xx.py 為你的學(xué)生成績管理系統(tǒng)文件的絕對地址

打包完成后,提示信息倒數(shù)第二行:Appending語句后面即為exe文件位置,若無特殊顯示,則在當(dāng)前目錄父文件下

以上就是關(guān)于“python編寫學(xué)生成績管理系統(tǒng)的邏輯結(jié)構(gòu)及功能怎么實現(xiàn)”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI