使用python實現(xiàn)學生信息管理系統(tǒng)
本文實例為大家分享了python實現(xiàn)學生信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
學生管理系統(tǒng)的開發(fā)步驟:
1、顯示學生管理系統(tǒng)的功能菜單
2、接收用戶輸入的功能選項
3、判斷用戶輸入的功能選項,并完成相關(guān)的操作
把功能代碼抽取到函數(shù)的目的:提供功能代碼的復用性,減少功能代碼的冗余。
# 學生列表,專門來負責管理每一個學生信息 student_list = [] # 顯示學生管理系統(tǒng)菜單的功能函數(shù) def show_menu(): print("=================== 學生管理系統(tǒng)V1.0 ===================") print("1. 添加學生") print("2. 刪除學生") print("3. 修改學生信息") print("4. 查詢學生信息") print("5. 顯示所有學生信息") print("6. 退出") # 添加學生的功能函數(shù) def add_student(): # 實現(xiàn)添加學生的功能 name = input("請輸入的您的姓名:") age = input("請輸入的您的年齡:") sex = input("請輸入的您的性別:") # 每一個學生信息是字典類型,需要把這個三項數(shù)據(jù)組裝到字典里面 student_dict = {"name": name, "age": age, "sex": sex} # 把學生字典信息添加到列表 student_list.append(student_dict) # 顯示所有學生的功能函數(shù) def show_all_student(): # 實現(xiàn)顯示所有學生的功能 for index, student_dict in enumerate(student_list): # 學號 = 下標 + 1 student_no = index + 1 print("學號: %d 姓名: %s 年齡: %s 性別: %s" % (student_no, student_dict["name"], student_dict["age"], student_dict["sex"])) # 刪除學生的功能函數(shù) def remove_student(): # 1. 接收要刪除學生的學號 student_no = int(input("請輸入您要刪除學生的學號:")) # 2. 根據(jù)學生生成下標 index = student_no - 1 # 判斷下標是否合法 if 0 <= index < len(student_list): # 3. 根據(jù)下標從列表中刪除指定數(shù)據(jù) student_dict = student_list.pop(index) print("%s, 刪除成功!" % student_dict["name"]) else: print("請輸入合法的學號!") # 修改學生信息的功能函數(shù) def modify_student(): # 1. 接收要修改學生的學號 student_no = int(input("請輸入您要修改學生的學號:")) # 2. 根據(jù)學生生成下標 index = student_no - 1 # 判斷下標是否合法 if 0 <= index < len(student_list): # 3. 根據(jù)下標獲取對應(yīng)的學生字典信息 modify_student_dict = student_list[index] # 4. 根據(jù)字典修改學生信息 modify_student_dict["name"] = input("請輸入您修改后的姓名:") modify_student_dict["age"] = input("請輸入您修改后的年齡:") modify_student_dict["sex"] = input("請輸入您修改后的性別:") print("修改成功") else: print("請輸入您的合法學號!") # 查詢學生 def query_student(): # 1. 接收用戶入要查詢學生的姓名 name = input("請輸入要查詢學生的姓名:") # 2. 遍歷學生列表,一次判斷學生的姓名是否是指定名字 for index, student_dict in enumerate(student_list): if student_dict["name"] == name: # 生成學生 student_no = index + 1 # 3. 如果找到了則輸出學生信息,則停止循環(huán) print("學號: %d 姓名: %s 年齡: %s 性別: %s" % (student_no, student_dict["name"], student_dict["age"], student_dict["sex"])) break else: # 4. 遍歷完都沒有找到,需要輸出該用戶不存在 print("對不起,您查找的學生信息不存在!") # 學生管理系統(tǒng)的開發(fā)步驟 # 提示:由于系統(tǒng)需要一直運行,需要把以上三個步驟放到死循環(huán)里面,這樣可以保存程序一直運行。 # 定義程序的入口函數(shù),程序第一個要執(zhí)行的函數(shù) def start(): while True: # 1. 顯示學生管理系統(tǒng)的功能菜單 show_menu() # 2. 接收用戶輸入的功能選項 menu_option = input("請輸入您要操作的功能選項:") # 3. 判斷用戶輸入的功能選項,并完成相關(guān)的操作 if menu_option == "1": print("添加學生") add_student() elif menu_option == "2": print("刪除學生") remove_student() elif menu_option == "3": print("修改學生信息") modify_student() elif menu_option == "4": print("查詢學生信息") query_student() elif menu_option == "5": print("顯示所有學生信息") show_all_student() elif menu_option == "6": print("退出") break # 啟動程序 start()
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python實現(xiàn)批量上傳本地maven庫到nexus
這篇文章主要為大家詳細介紹了如何使用Python實現(xiàn)批量上傳本地maven庫到nexus,文中的示例代碼講解詳細,具有一定的借鑒價值,需要的小伙伴可以參考下2024-01-01現(xiàn)代Python編程的四個關(guān)鍵點你知道幾個
這篇文章主要為大家詳細介紹了Python編程的四個關(guān)鍵點,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-02-02python通過colorama模塊在控制臺輸出彩色文字的方法
這篇文章主要介紹了python通過colorama模塊在控制臺輸出彩色文字的方法,實例分析了colorama模塊的功能及相關(guān)使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03pytorch使用voc分割數(shù)據(jù)集訓練FCN流程講解
這篇文章主要介紹了pytorch使用voc分割數(shù)據(jù)集訓練FCN流程,圖像分割發(fā)展過程也經(jīng)歷了傳統(tǒng)算法到深度學習算法的轉(zhuǎn)變,傳統(tǒng)的分割算法包括閾值分割、分水嶺、邊緣檢測等等2022-12-12