使用Python實(shí)現(xiàn) 學(xué)生學(xué)籍管理系統(tǒng)
大家好,今天跟大家分享一個用Python實(shí)現(xiàn)的學(xué)生學(xué)籍管理系統(tǒng):
該代碼主體由五個函數(shù)組成:
1.add_stu() 添加
2.del_stu() 刪除
3.print_stu()打印
4.exit_stu() 退出
5.system() 主函數(shù)
1.add_stu()
此段函數(shù)作用:把輸入的值存入字典newstu中,并將字典存入列表stu中
def add_stu():
newstu = {
'num':int(input("請輸入學(xué)號:"'')),
'name':input("請輸入姓名:"''),
'sex':input("請輸入性別:"'')
}
stu.append(newstu) #stu是定義的列表,可在下面的完整代碼中查找
return system()

2.del_stu()
此段函數(shù)作用:根據(jù)輸入學(xué)號,查找列表中的字典鍵值是否存入,若存入,將該字典從列表中刪除
def del_stu():
delstus = int(input("請輸入要刪除的學(xué)生學(xué)號:"))
k = 0 #循環(huán)遞增變量,用來判斷要刪除的字典在列表中的位置
for temp in stu:
k+=1
if delstus in range(temp['num'],temp['num']-1,-1):
#這里的temp變量相當(dāng)于列表中的字典,通過查找鍵值是否相匹配,并用到range函數(shù)(start,stop,step)
print("該學(xué)號已找到")
break
del stu[( k - 1 )]#刪除列表中的字典
print("刪除成功")
return system()

3.print_stu()
此段函數(shù)作用:把列表中的字典以值的形式遍歷出來
def print_stu():
i = 1
j = 0
k = 1
print("=================================")
print("學(xué)生信息如下:")
print("=================================")
print("序號\t學(xué)號\t姓名\t性別")
for s in stu:#遍歷列表
for cla in s.values(): #字典中的按值索引
if j%3 == 0:#第一個if用來實(shí)現(xiàn):序號遞增并換行
print("\n")
print(k,end = '.\t')
k+=1
print(cla,end = '\t')
if i%3 == 0:#第二個if用來實(shí)現(xiàn):每輸出一個字典就換行
print("\n")
i+=1
j+=1
print("\n")
return system()

4.exit_stu()
此段函數(shù)作用:人機(jī)交互,退出
def exit_stu():
x = input("是否退出?( YES or NO ) : ")
if x == 'YES':
print("***Repl Closed*** ")
else:
return system()

5.system_stu()
主函數(shù)
def system():
print("=================================")
print("學(xué)生管理系統(tǒng)v1.0")
print("1.添加學(xué)生信息")
print("2.刪除學(xué)生信息")
print("3.顯示所有的學(xué)生信息")
print("0.退出系統(tǒng)")
print("=================================")
x = int(input("請輸入功能對應(yīng)的數(shù)字: "))
if( x == 1):
add_stu()
elif( x == 2):
del_stu()
elif( x == 3):
print_stu()
elif( x == 0):
exit_stu()
else:
return system()

完整代碼
stu = []
def add_stu():
newstu = {
'num':int(input("請輸入學(xué)號:"'')),
'name':input("請輸入姓名:"''),
'sex':input("請輸入性別:"'')
}
stu.append(newstu)
return system()
def del_stu():
delstus = int(input("請輸入要刪除的學(xué)生學(xué)號:"))
k = 0
for temp in stu:
k+=1
if delstus in range(temp['num'],temp['num']-1,-1):
print("該學(xué)號已找到")
break
del stu[( k - 1 )]
print("刪除成功")
return system()
def print_stu():
i = 1
j = 0
k = 1
print("=================================")
print("學(xué)生信息如下:")
print("=================================")
print("序號\t學(xué)號\t姓名\t性別")
for s in stu:
for cla in s.values():
if j%3 == 0:
print("\n")
print(k,end = '.\t')
k+=1
print(cla,end = '\t')
if i%3 == 0:
print("\n")
i+=1
j+=1
print("\n")
return system()
def exit_stu():
x = input("是否退出?( YES or NO ) : ")
if x == 'YES':
print("***Repl Closed*** ")
else:
return system()
def system():
print("=================================")
print("學(xué)生管理系統(tǒng)v1.0")
print("1.添加學(xué)生信息")
print("2.刪除學(xué)生信息")
print("3.顯示所有的學(xué)生信息")
print("0.退出系統(tǒng)")
print("=================================")
x = int(input("請輸入功能對應(yīng)的數(shù)字: "))
if( x == 1):
add_stu()
elif( x == 2):
del_stu()
elif( x == 3):
print_stu()
elif( x == 0):
exit_stu()
else:
return system()
system()



難點(diǎn)
1.在列表中,按學(xué)號索引字典
2. 打印列表時的換行和序號
總結(jié)
以上所述是小編給大家介紹的使用Python實(shí)現(xiàn) 學(xué)生學(xué)籍管理系統(tǒng),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
- 用python實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- python實(shí)現(xiàn)學(xué)生管理系統(tǒng)開發(fā)
- python實(shí)現(xiàn)簡易版學(xué)生成績管理系統(tǒng)
- python實(shí)現(xiàn)簡單學(xué)生信息管理系統(tǒng)
- python學(xué)生管理系統(tǒng)的實(shí)現(xiàn)
- python學(xué)生信息管理系統(tǒng)實(shí)現(xiàn)代碼
- 基于python實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
- python創(chuàng)建學(xué)生成績管理系統(tǒng)
- python創(chuàng)建學(xué)生管理系統(tǒng)
- 基于Python實(shí)現(xiàn)簡單學(xué)生管理系統(tǒng)
相關(guān)文章
使用python批量轉(zhuǎn)換文件編碼為UTF-8的實(shí)現(xiàn)
這篇文章主要介紹了使用python批量轉(zhuǎn)換文件編碼為UTF-8的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04
python檢測lvs real server狀態(tài)
這篇文章主要介紹了用python檢測lvs real server狀態(tài)的示例,大家參考使用吧2014-01-01
使用Python將字符串轉(zhuǎn)換為格式化的日期時間字符串
這篇文章主要介紹了使用Python將字符串轉(zhuǎn)換為格式化的日期時間字符串,需要的朋友可以參考下2019-09-09
基于python實(shí)現(xiàn)MUI區(qū)域滾動
這篇文章主要介紹的是python實(shí)現(xiàn)MUI區(qū)域滾動,MUI提供了區(qū)域滾動的組件,使用時遵循DOM結(jié)構(gòu)就可以,下面來看看文章具體的實(shí)現(xiàn)內(nèi)容,需要的朋友可以參考一下2021-11-11
Pandas數(shù)據(jù)分組統(tǒng)計的實(shí)現(xiàn)示例
對數(shù)據(jù)進(jìn)行分組統(tǒng)計,主要適用DataFrame對象的groupby()函數(shù),本文就來詳細(xì)的介紹下Pandas數(shù)據(jù)分組統(tǒng)計的實(shí)現(xiàn),具有一定的參考價值,感興趣的可以了解下2023-11-11

