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

Python實現(xiàn)學(xué)生管理系統(tǒng)(面向?qū)ο蟀?

 更新時間:2021年09月10日 15:25:06   作者:王濤濤.  
這篇文章主要為大家詳細介紹了Python實現(xiàn)面向?qū)ο蟀娴膶W(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

實現(xiàn)從面向過程到面向?qū)ο蟮倪^度,通過更改前面的學(xué)生管理系統(tǒng)實現(xiàn)面向?qū)ο?,也證明了面向過程可以完美過度到面向?qū)ο?,從而為以后的程序進步做了進一步優(yōu)化,方便以后的程序更改。

完整代碼如下:

student_main模塊中的代碼

import student_tools


class Student(student_tools.StudentT):

    def __init__(self):
        self.user=['wangtaotao']
        self.pwd=['123456']
        student_tools.StudentT.__init__(self)

    #登錄
    def denglu(self):
        users = input("請輸入您的用戶名:")
        pwds = input("請輸入您的密碼:")
        if users in self.user and pwds in self.pwd:
            self.student()
        else:
            print("賬號或密碼不正確,請重新輸入")

    #注冊
    def zhuce(self):
        users=input("請輸入您要注冊的用戶名:")
        pwds=input("請輸入您要注冊的密碼:")
        self.user.append(users)
        self.pwd.append(pwds)
        print()
        print("注冊成功!")
        print()

    #登錄界面
    def dljiemian(self):

        while True:
            print("---------------------------")
            print("    學(xué)生管理系統(tǒng)登陸界面 V1.0  ")
            print("                           ")
            print("        1:登   錄           ")
            print("        2:注   冊           ")
            print("        3:退   出           ")
            print("                           ")
            print("---------------------------")
            xx=input("請輸入您的選擇:")
            #1.登錄
            if xx=='1':
                self.denglu()
            elif xx=='2':
            #2.注冊
                self.zhuce()
            elif xx=='3':
            #3.退出
                print()
                print("成功退出!")
                print()
                break
            else:
                print("輸入錯誤,請重新輸入")


    #學(xué)生管理系統(tǒng)
    def student(self):
        # 調(diào)用student_tools模塊中的讀取文件函數(shù)
        super().read_file()
        while True:
            #調(diào)用student_tools模塊中的界面函數(shù)
            super().jiemian()

            x=input("請輸入您的選擇:")
            #添加學(xué)生
            if x=='1':
                super().add()
            #刪除學(xué)生
            elif x=='2':
                super().dele()
            #修改學(xué)生
            elif x=='3':
                super().xiugai()
            #查詢學(xué)生
            elif x=='4':
                super().find()
            #顯示所有學(xué)生
            elif x=='5':
                super().showall()
            #保存數(shù)據(jù)至文件中
            elif x=='6':
                super().save_file()
            #退出學(xué)生管理系統(tǒng),返回上一層登錄界面系統(tǒng)
            elif x=='7':
                print()
                print("成功退出學(xué)生管理系統(tǒng)!")
                break
            else:
                print()
                print("輸入錯誤,請重新輸入")
                print()

    #調(diào)用最先執(zhí)行的登錄界面函數(shù)
if __name__=='__main__':
    wtt=Student()
    wtt.dljiemian()

student_tools模塊中的代碼

import os


class StudentT(object):

    def __init__(self):
        self.student_list=[]
        self.student_dict={}


    #學(xué)生管理系統(tǒng)界面
    @staticmethod
    def jiemian():
        print("---------------------------")
        print("      學(xué)生管理系統(tǒng) V1.0")
        print("                           ")
        print("      1:添加學(xué)生"            )
        print("      2:刪除學(xué)生"            )
        print("      3:修改學(xué)生"            )
        print("      4:查詢學(xué)生"            )
        print("      5:顯示所有學(xué)生"         )
        print("      6:保存數(shù)據(jù)"            )
        print("      7:退出系統(tǒng)"            )
        print("                           ")
        print("---------------------------")


    #添加學(xué)生
    def add(self):
        name=input("請輸入錄入學(xué)生姓名:")
        cls=input("請輸入學(xué)生班級:")
        age=input("請輸入錄入學(xué)生年齡:")
        phone=input("請輸入錄入學(xué)生手機號:")
        addr=input("請輸入錄入學(xué)生家庭住址:")

        self.student_dict={"name":name,"class":cls,"age":age,"phone":phone,"address":addr}

        self.student_list.append(self.student_dict)
        print()
        print("-----添加學(xué)生信息界面-----")
        print()
        print("姓名\t\t","班級\t\t","年齡\t\t","電話號\t\t","家庭住址\t\t")
        for student_dict_1 in self.student_list:
            print("%s\t\t%s\t\t%s\t\t%s\t\t%s" %(student_dict_1["name"],
                                                 student_dict_1["class"],
                                                 student_dict_1["age"],
                                                 student_dict_1["phone"],
                                                 student_dict_1["address"]))
        print()
        print("錄入成功!")
        print()

    #刪除學(xué)生
    def dele(self):
        name_del=input("請輸入想要刪除的學(xué)生姓名:")
        for student_dict_1 in self.student_list:
            if name_del in student_dict_1["name"]:
                self.student_list.remove(student_dict_1)
                print()
                print("刪除%s信息成功!" % name_del)
                print()
                break
        else:
            print()
            print("您輸入的學(xué)生姓名錯誤,請重新輸入")
            print()
    #修改學(xué)生
    def xiugai(self):
        name_xiugai=input("請輸入想要修改的學(xué)生姓名:")


        for student_dict_1 in self.student_list:

            if name_xiugai == student_dict_1["name"]:
                print()
                print("-----修改界面-----")
                print()
                print("姓名\t\t", "班級\t\t", "年齡\t\t", "電話號\t\t", "家庭住址\t\t")
                print("%s\t\t%s\t\t%s\t\t%s\t\t%s" %(student_dict_1["name"],
                                                     student_dict_1["class"],
                                                     student_dict_1["age"],
                                                     student_dict_1["phone"],
                                                     student_dict_1["address"]))
                #回車不修改

                student_dict_1["name"]=self.new_input(student_dict_1["name"],"請輸入修改后的學(xué)生姓名[回車不修改]:")
                student_dict_1["class"]=self.new_input(student_dict_1["class"],"請輸入修改后的學(xué)生班級[回車不修改]:")
                student_dict_1["age"]=self.new_input(student_dict_1["age"],"請輸入修改后的學(xué)生年齡[回車不修改]:")
                student_dict_1["phone"]=self.new_input(student_dict_1["phone"],"請輸入修改后的學(xué)生手機號[回車不修改]:")
                student_dict_1["address"]=self.new_input(student_dict_1["address"],"請輸入修改后的學(xué)生家庭地址[回車不修改]:")
                print()
                print("修改成功!")
                print()
                break
        else:
            print()
            print("您輸入的學(xué)生姓名錯誤,請重新輸入")
            print()

    #查找學(xué)生
    def find(self):
        find_name=input("請輸入需要查找的學(xué)生姓名:")
        for student_dict_1 in self.student_list:

            if find_name == student_dict_1["name"]:
                print()
                print("-----查詢結(jié)果界面-----")
                print()
                print("姓名\t\t", "班級\t\t", "年齡\t\t", "電話號\t\t", "家庭住址\t\t")
                print("%s\t\t%s\t\t%s\t\t%s\t\t%s" % (student_dict_1["name"],
                                                      student_dict_1["class"],
                                                      student_dict_1["age"],
                                                      student_dict_1["phone"],
                                                      student_dict_1["address"]))
            else:
                print()
                print("-----查詢結(jié)果界面-----")
                print()
                print("無此學(xué)生信息")

    #顯示所有學(xué)生信息
    def showall(self):

        if len(self.student_list)>0:
            print()
            print("-----顯示所有學(xué)生信息-----")
            print()
            print("姓名\t\t", "班級\t\t", "年齡\t\t", "電話號\t\t", "家庭住址\t\t")
            for student_dict_1 in self.student_list:

                print("%s\t\t%s\t\t%s\t\t%s\t\t%s" % (student_dict_1["name"],
                                                      student_dict_1["class"],
                                                      student_dict_1["age"],
                                                      student_dict_1["phone"],
                                                      student_dict_1["address"]))
        else:
            print()
            print("暫無數(shù)據(jù)!")
            print()
    #設(shè)置用戶不輸入內(nèi)容返回原值,輸入內(nèi)容返回新內(nèi)容
    def new_input(self,yuanzhi,message):
        self.input_str=input(message)

        if len(self.input_str)>0:
            return self.input_str
        else:
            return yuanzhi


    #保存數(shù)據(jù)至文件中
    def save_file(self):

        f = open("student2.txt", 'w', encoding='utf-8')
        f.write(str(self.student_list))
        f.close()
        print("數(shù)據(jù)保存至student1.txt文件成功!")


    #將數(shù)據(jù)讀取至變量中
    def read_file(self):

         if os.path.exists('student2.txt'):
            f = open('student2.txt', 'r', encoding='utf-8')
            ret = f.read()

            self.student_list=eval(ret)
            f.close()
            print("數(shù)據(jù)讀取成功!")

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

相關(guān)文章

  • 使用Python爬蟲庫BeautifulSoup遍歷文檔樹并對標簽進行操作詳解

    使用Python爬蟲庫BeautifulSoup遍歷文檔樹并對標簽進行操作詳解

    今天為大家介紹下Python爬蟲庫BeautifulSoup遍歷文檔樹并對標簽進行操作的詳細方法與函數(shù)
    2020-01-01
  • 淺析AST抽象語法樹及Python代碼實現(xiàn)

    淺析AST抽象語法樹及Python代碼實現(xiàn)

    Abstract Syntax Tree抽象語法樹簡寫為ATS,是相當于用樹結(jié)構(gòu)將代碼程式表現(xiàn)出來的一種數(shù)據(jù)結(jié)構(gòu),這里我們就來淺析AST抽象語法樹及Python代碼實現(xiàn)
    2016-06-06
  • Python3分析處理聲音數(shù)據(jù)的例子

    Python3分析處理聲音數(shù)據(jù)的例子

    今天小編就為大家分享一篇Python3分析處理聲音數(shù)據(jù)的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • 使用Python和OpenCV檢測圖像中的物體并將物體裁剪下來

    使用Python和OpenCV檢測圖像中的物體并將物體裁剪下來

    這篇文章主要介紹了使用Python和OpenCV檢測圖像中的物體并將物體裁剪下來,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • python將一個英文語句以單詞為單位逆序排放的方法

    python將一個英文語句以單詞為單位逆序排放的方法

    今天小編就為大家分享一篇python將一個英文語句以單詞為單位逆序排放的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • pycharm安裝django框架詳細圖文教程(指定版本)

    pycharm安裝django框架詳細圖文教程(指定版本)

    這篇文章主要給大家介紹了關(guān)于pycharm安裝django框架(指定版本)的相關(guān)資料,PyCharm是一種Python?IDE,帶有一整套可以幫助用戶在使用Python語言開發(fā)時提高其效率的工具,需要的朋友可以參考下
    2023-10-10
  • Python?中strip()函數(shù)詳細說明及使用方法

    Python?中strip()函數(shù)詳細說明及使用方法

    strip()函數(shù)是Python字符串方法之一,用于處理字符串的前導(dǎo)和尾隨空白字符,它返回一個新字符串,該字符串是原始字符串去除前導(dǎo)和尾隨空格(包括空格、制表符、換行符等)后的結(jié)果,這篇文章主要介紹了Python?中strip()函數(shù)詳細說明及使用方法,需要的朋友可以參考下
    2024-02-02
  • Python 3.6 -win64環(huán)境安裝PIL模塊的教程

    Python 3.6 -win64環(huán)境安裝PIL模塊的教程

    PIL功能非常強大,但API卻非常簡單易用。這篇文章主要介紹了Python 3.6 -win64環(huán)境安裝PIL模塊的教程,需要的朋友可以參考下
    2019-06-06
  • Django解決frame拒絕問題的方法

    Django解決frame拒絕問題的方法

    這篇文章主要介紹了Django解決frame拒絕問題的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • python使用Pyinstaller如何打包整個項目

    python使用Pyinstaller如何打包整個項目

    這篇文章主要介紹了python使用Pyinstaller如何打包整個項目,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11

最新評論