欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python學(xué)生信息管理系統(tǒng)實(shí)現(xiàn)代碼

 更新時(shí)間:2021年06月22日 14:02:35   作者:xiaoxaoyu  
這篇文章主要為大家詳細(xì)介紹了python學(xué)生信息管理系統(tǒng)的實(shí)現(xiàn)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

python實(shí)現(xiàn)學(xué)生信息管理系統(tǒng),供大家參考,具體內(nèi)容如下

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import os


# 主函數(shù)
def main():
    ctrl = True
    while (ctrl):
        menu()
        option = input("請(qǐng)選擇:")
        option_str = re.sub("\D", "", option)
        if option_str in ['0', '1', '2', '3', '4', '5', '6', '7']:
            option_int = int(option_str)
            if option_int == 0:
                print("您已退出學(xué)生信息管理系統(tǒng)!")
                ctrl = False
            elif option_int == 1:
                insert()
            elif option_int == 2:
                search()
            elif option_int == 3:
                delete()
            elif option_int == 4:
                modify()
            elif option_int == 5:
                sort()
            elif option_int == 6:
                total()
            elif option_int == 7:
                show()


# 顯示主菜單
def menu():
    print("""
    -------------------學(xué)生信息管理系統(tǒng)---------------------
    ======================功能菜單=========================
    
    1 錄入學(xué)生信息
    2 查找學(xué)生信息
    3 刪除學(xué)生信息
    4 修改學(xué)生信息
    5 排序
    6 統(tǒng)計(jì)學(xué)生總?cè)藬?shù)
    7 顯示所有學(xué)生信息
    0 退出系統(tǒng)
    ======================================================
    說(shuō)明:通過(guò)數(shù)字或上下方向鍵選擇菜單
    ------------------------------------------------------
    """)


# 向指定文件寫(xiě)入指定內(nèi)容的函數(shù)
filename = "students.txt"


def save(student):
    try:
        students_txt = open(filename, "a")
    except:
        students_txt = open(filename, "w")
    for info in student:
        students_txt.write(str(info) + "\n")
    students_txt.close()


#     1 錄入學(xué)生信息
def insert():
    studentList = []
    mark = True
    while mark:
        id = input("請(qǐng)輸入ID(如1001):")
        if not id:
            break
        name = input("請(qǐng)輸入名字:")
        if not name:
            break
        try:
            english = int(input("請(qǐng)輸入英語(yǔ)成績(jī):"))
            python = int(input("請(qǐng)輸入Python成績(jī):"))
            c = int(input("請(qǐng)輸入C語(yǔ)言成績(jī):"))
        except:
            print("輸入無(wú)效,不是整型數(shù)值....重新錄入信息")
            continue
        # 信息保存到字典
        student = {"id": id, "name": name, "english": english, "python": python, "C語(yǔ)言": c}
        studentList.append(student)
        inputMark = input("是否繼續(xù)添加?(y/n):")
        if inputMark == "y":
            mark = True
        else:
            mark = False
        save(studentList)
        print("學(xué)生信息錄入完畢!")


#     2 查找學(xué)生信息
def search():
    mark = True
    student_query = []
    while mark:
        id = ""
        name = ""
        if os.path.exists(filename):
            mode = input("按ID查輸入1,按姓名查輸入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') as file:
                student = file.readlines()
                for list in student:
                    d = dict(eval(list))
                    if id is not "":
                        if d['id'] == id:
                            student_query.append(d)
                    elif name is not "":
                        if d['name'] == name:
                            student_query.append(d)
                show_student(student_query)
                student_query.clear()
                inputMark = input("是否繼續(xù)查詢(xún)?(y/n):")
                if inputMark == "y":
                    mark = True
                else:
                    mark = False
        else:
            print("暫未保存數(shù)據(jù)信息...")
            return


def show_student(studentList):
    if not studentList:
        print("無(wú)數(shù)據(jù)信息")
        return
    format_title = "{:^6}{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^10}"
    print(format_title.format("ID", "名字", "英語(yǔ)成績(jī)", "Python成績(jī)", "C語(yǔ)言成績(jī)", "總成績(jī)"))
    format_data = "{:^6}{:^12}\t{:^12}\t{:^12}\t{:^12}\t{:^12}"
    for info in studentList:
        print(format_data.format(info.get("id"), info.get("name"), str(info.get("english")), str(info.get("python")),
                                 str(info.get("C語(yǔ)言")),
                                 str(info.get("english")+info.get("python")+info.get("C語(yǔ)言")).center(12)))


#     3 刪除學(xué)生信息
def delete():
    mark = True
    while mark:
        studentId = input("請(qǐng)輸入要?jiǎng)h除的學(xué)生ID:")
        if studentId is not "":
            if os.path.exists(filename):
                with open(filename, 'r') as rfile:
                    student_old = rfile.readlines()
            else:
                student_old = []
            ifdel = False
            if student_old:
                with open(filename, 'w') as wfile:
                    d = {}
                    for list in student_old:
                        d = dict(eval(list))
                        if d['id'] != studentId:
                            wfile.write(str(d) + "\n")
                        else:
                            ifdel = True
                    if ifdel:
                        print("ID為%s的學(xué)生信息已經(jīng)被刪除..." % studentId)
                    else:
                        print("沒(méi)有找到ID為%s的學(xué)生信息..." % studentId)
            else:
                print("無(wú)學(xué)生信息...")
                break
            show()
            inputMark = input("是否繼續(xù)刪除?(y/n):")
            if inputMark == "y":
                mark = True
            else:
                mark = False


#     4 修改學(xué)生信息
def modify():
    show()
    if os.path.exists(filename):
        with open(filename, 'r') as rfile:
            student_old = rfile.readlines()
    else:
        return
    studentid = input("請(qǐng)輸入要修改的學(xué)生ID:")
    with open(filename, "w") as wfile:
        for student in student_old:
            d = dict(eval(student))
            if d["id"] == studentid:
                print("找到了這名學(xué)生,可以修改他的信息!")
                while True:
                    try:
                        d["name"] = input("請(qǐng)輸入姓名:")
                        d["english"] = int(input("請(qǐng)輸入英語(yǔ)成績(jī):"))
                        d["python"] = int(input("請(qǐng)輸入Python成績(jī):"))
                        d["C語(yǔ)言"] = int(input("請(qǐng)輸入C語(yǔ)言成績(jī):"))
                    except:
                        print("輸入信息有誤,重新輸入")
                    else:
                        break
                student = str(d)
                wfile.write(student + "\n")
                print("修改成功!")
            else:
                wfile.write(student)
    mark = input("是否繼續(xù)修改其他學(xué)生信息?(y/n):")
    if mark == "y":
        modify()


#     5 排序
def sort():
    show()
    if os.path.exists(filename):
        with open(filename, 'r') as file:
            student_old = file.readlines()
            student_new = []
        for list in student_old:
            d = dict(eval(list))
            student_new.append(d)
    else:
        return
    ascOrDesc = input("請(qǐng)選擇(0升序;1降序):")
    if ascOrDesc == "0":
        ascOrDescBool = False
    elif ascOrDesc == "1":
        ascOrDescBool = True
    else:
        print("您的輸入有誤,請(qǐng)重新輸入!")
        sort()
    mode = input("請(qǐng)選擇排序方式(1按英語(yǔ)排序;2按Python排序;3按C語(yǔ)言排序;0按總成績(jī)排序)")
    if mode == "1":
        student_new.sort(key=lambda x: x["english"], reverse=ascOrDescBool)
    elif mode == "2":
        student_new.sort(key=lambda x: x["python"], reverse=ascOrDescBool)
    elif mode == "3":
        student_new.sort(key=lambda x: x["C語(yǔ)言"], reverse=ascOrDescBool)
    elif mode == "0":
        student_new.sort(key=lambda x: x["english"] + x["python"] + x["C語(yǔ)言"], reverse=ascOrDescBool)
    else:
        print("您的輸入有誤,請(qǐng)重新輸入!")
        sort()
    show_student(student_new)


#     6 統(tǒng)計(jì)學(xué)生總?cè)藬?shù)
def total():
    if os.path.exists(filename):
        with open(filename, 'r') as rfile:
            student_old = rfile.readlines()
            if student_old:
                print("一共有%s名學(xué)生" % len(student_old))
            else:
                print("還沒(méi)有錄入學(xué)生信息!")
    else:
        print("暫未保存數(shù)據(jù)信息...")


#     7 顯示所有學(xué)生信息
def show():
    student_new = []
    if os.path.exists(filename):
        with open(filename, 'r') as rfile:
            student_old = rfile.readlines()
        for list in student_old:
            student_new.append(eval(list))
        if student_new:
            show_student(student_new)
    else:
        print("暫未保存數(shù)據(jù)信息...")


#     0 退出系統(tǒng)


if __name__ == '__main__':
    main()

安裝pyinstaller打包成可執(zhí)行exe文件

pip install pyinstaller
...

(pydemo) D:\JavaProjects\PythonProject\01學(xué)生信息管理系統(tǒng)>pyinstaller --version
4.3
(pydemo) D:\JavaProjects\PythonProject\01學(xué)生信息管理系統(tǒng)>pyinstaller -F D:\JavaProjects\PythonProject\01學(xué)生信息管理系統(tǒng)\StuManagerSys.py

在下面的路徑即可找到打包后的exe文件

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

相關(guān)文章

  • 通過(guò)python-pptx模塊操作ppt文件的方法

    通過(guò)python-pptx模塊操作ppt文件的方法

    這篇文章主要介紹了通過(guò)python-pptx模塊操作ppt文件的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,本文給大家介紹的需要的朋友可以參考下
    2020-12-12
  • python list轉(zhuǎn)dict示例分享

    python list轉(zhuǎn)dict示例分享

    這篇文章主要介紹了python list轉(zhuǎn)dict的使用方法,大家參考使用吧
    2014-01-01
  • 利用Python?實(shí)現(xiàn)分布式計(jì)算

    利用Python?實(shí)現(xiàn)分布式計(jì)算

    這篇文章主要介紹了利用Python?實(shí)現(xiàn)分布式計(jì)算,文章通過(guò)借助于?Ray展開(kāi)對(duì)分布式計(jì)算的實(shí)現(xiàn),感興趣的小伙伴可以參考一下
    2022-05-05
  • python opencv檢測(cè)目標(biāo)顏色的實(shí)例講解

    python opencv檢測(cè)目標(biāo)顏色的實(shí)例講解

    下面小編就為大家分享一篇python opencv檢測(cè)目標(biāo)顏色的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • Python基于列表list實(shí)現(xiàn)的CRUD操作功能示例

    Python基于列表list實(shí)現(xiàn)的CRUD操作功能示例

    這篇文章主要介紹了Python列表list實(shí)現(xiàn)的CRUD操作功能,結(jié)合實(shí)例形式分析了Python基于列表list實(shí)現(xiàn)用戶(hù)數(shù)據(jù)CRUD相關(guān)操作技巧,需要的朋友可以參考下
    2018-01-01
  • Python實(shí)現(xiàn)遍歷讀取文件或文件夾

    Python實(shí)現(xiàn)遍歷讀取文件或文件夾

    搞機(jī)器學(xué)習(xí)或者深度學(xué)習(xí)算法很多時(shí)候需要遍歷某個(gè)目錄讀取文件,特別是經(jīng)常需要讀取某個(gè)特定后綴的文件。本文為大家準(zhǔn)備了Python遍歷讀取文件或文件夾的示例代碼,需要的可以參考一下
    2022-08-08
  • Python常見(jiàn)異常的處理方式淺析

    Python常見(jiàn)異常的處理方式淺析

    異常指當(dāng)程序出現(xiàn)錯(cuò)誤后程序的處理方法,異常機(jī)制提供了程序正常退出的安全通道.當(dāng)出現(xiàn)錯(cuò)誤后,程序執(zhí)行的流程發(fā)生改變,程序的控制權(quán)轉(zhuǎn)移到異常處理器,如序列的下標(biāo)越界、打開(kāi)不存在的文件、空引用異常等
    2023-02-02
  • 淺談Python 字符串格式化輸出(format/printf)

    淺談Python 字符串格式化輸出(format/printf)

    下面小編就為大家?guī)?lái)一篇淺談Python 字符串格式化輸出(format/printf)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-07-07
  • 結(jié)合Python網(wǎng)絡(luò)爬蟲(chóng)做一個(gè)今日新聞小程序

    結(jié)合Python網(wǎng)絡(luò)爬蟲(chóng)做一個(gè)今日新聞小程序

    本篇文章介紹了我在開(kāi)發(fā)過(guò)程中遇到的一個(gè)問(wèn)題,以及解決該問(wèn)題的過(guò)程及思路,通讀本篇對(duì)大家的學(xué)習(xí)或工作具有一定的價(jià)值,需要的朋友可以參考下
    2021-09-09
  • PyTorch中permute的用法詳解

    PyTorch中permute的用法詳解

    今天小編就為大家分享一篇PyTorch中permute的用法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-12-12

最新評(píng)論