亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

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

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

用Python實現學生管理系統

發布時間:2021-06-24 10:51:25 來源:億速云 閱讀:141 作者:chen 欄目:開發技術

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

實現從面向過程到面向對象的過度,通過更改前面的學生管理系統實現面向對象,也證明了面向過程可以完美過度到面向對象,從而為以后的程序進步做了進一步優化,方便以后的程序更改。

完整代碼如下:

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("    學生管理系統登陸界面 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("輸入錯誤,請重新輸入")


    #學生管理系統
    def student(self):
        # 調用student_tools模塊中的讀取文件函數
        super().read_file()
        while True:
            #調用student_tools模塊中的界面函數
            super().jiemian()

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

    #調用最先執行的登錄界面函數
if __name__=='__main__':
    wtt=Student()
    wtt.dljiemian()

student_tools模塊中的代碼

import os


class StudentT(object):

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


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


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

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

        self.student_list.append(self.student_dict)
        print()
        print("-----添加學生信息界面-----")
        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()

    #刪除學生
    def dele(self):
        name_del=input("請輸入想要刪除的學生姓名:")
        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("您輸入的學生姓名錯誤,請重新輸入")
            print()
    #修改學生
    def xiugai(self):
        name_xiugai=input("請輸入想要修改的學生姓名:")


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

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

            if find_name == 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"]))
            else:
                print()
                print("-----查詢結果界面-----")
                print()
                print("無此學生信息")

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

        if len(self.student_list)>0:
            print()
            print("-----顯示所有學生信息-----")
            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("暫無數據!")
            print()
    #設置用戶不輸入內容返回原值,輸入內容返回新內容
    def new_input(self,yuanzhi,message):
        self.input_str=input(message)

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


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

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


    #將數據讀取至變量中
    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("數據讀取成功!")

到此,關于“用Python實現學生管理系統”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

绵阳市| 龙里县| 布尔津县| 景泰县| 昌宁县| 淳化县| 沙坪坝区| 高淳县| 元江| 明光市| 永年县| 道孚县| 余姚市| 宜昌市| 曲沃县| 夏津县| 贡觉县| 沧源| 天津市| 邳州市| 凌云县| 南丹县| 贞丰县| 福贡县| 潼南县| 潞西市| 象州县| 安庆市| 盘锦市| 新河县| 宜君县| 湘潭市| 闸北区| 延庆县| 紫金县| 宜阳县| 大石桥市| 大足县| 东乌珠穆沁旗| 乌拉特前旗| 白朗县|