溫馨提示×

溫馨提示×

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

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

用Python實現(xiàn)學(xué)生管理系統(tǒng)

發(fā)布時間:2021-06-24 10:51:25 來源:億速云 閱讀:140 作者:chen 欄目:開發(fā)技術(shù)

這篇文章主要介紹“用Python實現(xiàn)學(xué)生管理系統(tǒng)”,在日常操作中,相信很多人在用Python實現(xiàn)學(xué)生管理系統(tǒng)問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”用Python實現(xiàn)學(xué)生管理系統(tǒng)”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

實現(xiàn)從面向過程到面向?qū)ο蟮倪^度,通過更改前面的學(xué)生管理系統(tǒng)實現(xiàn)面向?qū)ο?,也證明了面向過程可以完美過度到面向?qū)ο?,從而為以后的程序進(jìn)步做了進(jìn)一步優(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é)生手機(jī)號:")
        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é)生手機(jī)號[回車不修改]:")
                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ù)讀取成功!")

到此,關(guān)于“用Python實現(xiàn)學(xué)生管理系統(tǒng)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向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