網站首頁 編程語言 正文
本文實例為大家分享了Python實現學生管理系統的具體代碼,供大家參考,具體內容如下
功能描述
1.分為兩個界面:(1)登錄和注冊界面 (2)學生管理系統界面
2.登錄功能和之前發布的圖書管理系統相同,登錄成功后可進入學生管理系統界面,這里不再敘述
3.系統功能(1)添加學生信息(2)刪除學生信息(3)修改學生信息(4)查詢學生信息(5)顯示所有學生信息(6)退出
4.有很多地方增加了優化,也進行了完善,如模塊導入、登錄注冊以及回車不修改等功能。整個程序代碼大概200行。
注意:代碼分為兩個模塊,需要在student_main模塊中啟動。student_main模塊中只負責輸入操作,而student_tools模塊中負責具體的學生信息系統操作實現功能。所以大家在拷貝代碼的時候記得創建兩個.py文件。
完整代碼如下
student_main模塊內容代碼:
import student_tools
user=['wangtaotao']
pwd=['123456']
#登錄
def denglu():
? ? users = input("請輸入您的用戶名:")
? ? pwds = input("請輸入您的密碼:")
? ? if users in user and pwds in pwd:
? ? ? ? student()
? ? else:
? ? ? ? print("賬號或密碼不正確,請重新輸入")
#注冊
def zhuce():
? ? users=input("請輸入您要注冊的用戶名:")
? ? pwds=input("請輸入您要注冊的密碼:")
? ? user.append(users)
? ? pwd.append(pwds)
? ? print()
? ? print("注冊成功!")
? ? print()
#登錄界面
def dljiemian():
? ? while True:
? ? ? ? print("---------------------------")
? ? ? ? print(" ? ?學生管理系統登陸界面 V1.0 ?")
? ? ? ? print(" ? ? ? ? ? ? ? ? ? ? ? ? ? ")
? ? ? ? print(" ? ? ? ?1:登 ? 錄 ? ? ? ? ? ")
? ? ? ? print(" ? ? ? ?2:注 ? 冊 ? ? ? ? ? ")
? ? ? ? print(" ? ? ? ?3:退 ? 出 ? ? ? ? ? ")
? ? ? ? print(" ? ? ? ? ? ? ? ? ? ? ? ? ? ")
? ? ? ? print("---------------------------")
? ? ? ? xx=input("請輸入您的選擇:")
? ? ? ? #1.登錄
? ? ? ? if xx=='1':
? ? ? ? ? ? denglu()
? ? ? ? elif xx=='2':
? ? ? ? #2.注冊
? ? ? ? ? ? zhuce()
? ? ? ? elif xx=='3':
? ? ? ? #3.退出
? ? ? ? ? ? print()
? ? ? ? ? ? print("成功退出!")
? ? ? ? ? ? print()
? ? ? ? ? ? break
? ? ? ? else:
? ? ? ? ? ? print("輸入錯誤,請重新輸入")
#學生管理系統
def student():
? ? while True:
? ? ? ? #調用student_tools模塊中的界面函數
? ? ? ? student_tools.jiemian()
? ? ? ? x=input("請輸入您的選擇:")
? ? ? ? #添加學生
? ? ? ? if x=='1':
? ? ? ? ? ? student_tools.add()
? ? ? ? #刪除學生
? ? ? ? elif x=='2':
? ? ? ? ? ? student_tools.dele()
? ? ? ? #修改學生
? ? ? ? elif x=='3':
? ? ? ? ? ? student_tools.xiugai()
? ? ? ? #查詢學生
? ? ? ? elif x=='4':
? ? ? ? ? ? student_tools.find()
? ? ? ? #顯示所有學生
? ? ? ? elif x=='5':
? ? ? ? ? ? student_tools.showall()
? ? ? ? #退出學生管理系統,返回上一層登錄界面系統
? ? ? ? elif x=='6':
? ? ? ? ? ? print()
? ? ? ? ? ? print("成功退出學生管理系統!")
? ? ? ? ? ? break
? ? ? ? else:
? ? ? ? ? ? print()
? ? ? ? ? ? print("輸入錯誤,請重新輸入")
? ? ? ? ? ? print()
#調用最先執行的登錄界面函數
dljiemian()
student_tools模塊內容代碼:
student_list=[]
student_dict={}
#學生管理系統界面
def jiemian():
? ? print("---------------------------")
? ? print(" ? ? ?學生管理系統 V1.0")
? ? print(" ? ? ? ? ? ? ? ? ? ? ? ? ? ")
? ? print(" ? ? ?1:添加學生" ? ? ? ? ? ?)
? ? print(" ? ? ?2:刪除學生" ? ? ? ? ? ?)
? ? print(" ? ? ?3:修改學生" ? ? ? ? ? ?)
? ? print(" ? ? ?4:查詢學生" ? ? ? ? ? ?)
? ? print(" ? ? ?5:顯示所有學生" ? ? ? ? )
? ? print(" ? ? ?6:退出系統" ? ? ? ? ? ?)
? ? print(" ? ? ? ? ? ? ? ? ? ? ? ? ? ")
? ? print("---------------------------")
#添加學生
def add():
? ? name=input("請輸入錄入學生姓名:")
? ? cls=input("請輸入學生班級:")
? ? age=input("請輸入錄入學生年齡:")
? ? phone=input("請輸入錄入學生手機號:")
? ? addr=input("請輸入錄入學生家庭住址:")
? ? student_dict={"name":name,"class":cls,"age":age,"phone":phone,"address":addr}
? ? student_list.append(student_dict)
? ? print()
? ? print("-----添加學生信息界面-----")
? ? print()
? ? print("姓名\t\t","班級\t\t","年齡\t\t","電話號\t\t","家庭住址\t\t")
? ? for student_dict_1 in 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():
? ? name_del=input("請輸入想要刪除的學生姓名:")
? ? for student_dict_1 in student_list:
? ? ? ? if name_del in student_dict_1["name"]:
? ? ? ? ? ? student_list.remove(student_dict_1)
? ? ? ? ? ? print()
? ? ? ? ? ? print("刪除%s信息成功!" % name_del)
? ? ? ? ? ? print()
? ? ? ? ? ? break
? ? else:
? ? ? ? print()
? ? ? ? print("您輸入的學生姓名錯誤,請重新輸入")
? ? ? ? print()
#修改學生
def xiugai():
? ? name_xiugai=input("請輸入想要修改的學生姓名:")
? ? for student_dict_1 in 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"]=new_input(student_dict_1["name"],"請輸入修改后的學生姓名[回車不修改]:")
? ? ? ? ? ? student_dict_1["class"]=new_input(student_dict_1["class"],"請輸入修改后的學生班級[回車不修改]:")
? ? ? ? ? ? student_dict_1["age"]=new_input(student_dict_1["age"],"請輸入修改后的學生年齡[回車不修改]:")
? ? ? ? ? ? student_dict_1["phone"]=new_input(student_dict_1["phone"],"請輸入修改后的學生手機號[回車不修改]:")
? ? ? ? ? ? student_dict_1["address"]=new_input(student_dict_1["address"],"請輸入修改后的學生家庭地址[回車不修改]:")
? ? ? ? ? ? print()
? ? ? ? ? ? print("修改成功!")
? ? ? ? ? ? print()
? ? ? ? ? ? break
? ? else:
? ? ? ? print()
? ? ? ? print("您輸入的學生姓名錯誤,請重新輸入")
? ? ? ? print()
#查找學生
def find():
? ? find_name=input("請輸入需要查找的學生姓名:")
? ? for student_dict_1 in 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():
? ? print()
? ? print("-----顯示所有學生信息-----")
? ? print()
? ? print("姓名\t\t", "班級\t\t", "年齡\t\t", "電話號\t\t", "家庭住址\t\t")
? ? for student_dict_1 in student_list:
? ? ? ? print(student_dict_1)
? ? ? ? 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"]))
#設置用戶不輸入內容返回原值,輸入內容返回新內容
def new_input(yuanzhi,message):
? ? input_str=input(message)
? ? if len(input_str)>0:
? ? ? ? return input_str
? ? else:
? ? ? ? return yuanzhi
原文鏈接:https://blog.csdn.net/WangTaoTao_/article/details/95054880
相關推薦
- 2022-09-24 python中的[1:]、[::-1]、X[:,m:n]和X[1,:]的使用_python
- 2022-11-02 React+Mobx基本使用、模塊化操作_React
- 2022-07-11 Springboot集成分布式事務Seata
- 2022-01-31 (數據)圖像預處理——image augmentation圖像增廣之cutout、Mixup、Cut
- 2023-11-20 python實現ssh傳遞文件
- 2022-05-27 C++?二叉樹的實現超詳細解析_C 語言
- 2022-05-11 多線程編程(下):線程同步&通信
- 2022-07-06 C#使用ADO.Net連接數據庫與DbProviderFactory實現多數據庫訪問_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支