當前位置:首頁 » 編程語言 » python信息管理系統

python信息管理系統

發布時間: 2024-11-03 08:03:39

Ⅰ 用Python編寫班級檔案管理系統

# -*- coding: cp936 -*-
class StuInfo:
def __init__(self):
self.Stu=[{"Sno":"1","Sname":"姓名","ChineseScore":64,"MathsScore":34,"EnglishScore":94,"ComputerScore":83},
{"Sno":"2","Sname":"姓名","ChineseScore":44,"MathsScore":24,"EnglishScore":44,"ComputerScore":71},
{"Sno":"3","Sname":"姓名","ChineseScore":74,"MathsScore":35,"EnglishScore":74,"ComputerScore":93},
{"Sno":"4","Sname":"姓名","ChineseScore":94,"MathsScore":54,"EnglishScore":24,"ComputerScore":73}]
self.attribute={"Sno":"學號",
"Sname":"姓名",
"ChineseScore":"語文成績",
"MathsScore":"數學成績",
"EnglishScore":"英語成績",
"ComputerScore":"計算機成績"
}
def _add(self):
'''添加'''
singleInfo={}
for i in self.attribute:
if "Score" in i:
singleInfo[i]=int(raw_input(self.attribute[i]+"\n"))
else:
singleInfo[i]=raw_input(self.attribute[i]+"\n").strip()
self.Stu.append(singleInfo)
print "添加成功OK"
for i in singleInfo:
print i,"=",singleInfo[i]

def _del(self):
"""刪除學號為Sno的記錄"""
Sno=raw_input("學號:\n")
self.Stu.remove(self.__getInfo(Sno))
print "刪除成功OK"

def _update(self):
"""更新數據"""
Sno=raw_input("學號\n").strip()
prefix="修改"
updateOperate={"1":"ChineseScore",
"2":"MathsScore",
"3":"EnglishScore",
"4":"ComputerScore"}
for i in updateOperate:
print i,"-->",prefix+self.attribute[updateOperate[i]]
getOperateNum=raw_input("選擇操作:\n")
if getOperateNum:
getNewValue=int(raw_input("輸入新的值:\n"))
record=self.__getInfo(Sno)
record[updateOperate[getOperateNum]]=getNewValue
print "修改"+record["Sname"]+"的"+str(updateOperate[getOperateNum])+"成績=",getNewValue,"\n成功OK"

def _getInfo(self):
"""查詢數據"""
while True:
print "1->學號查詢 2->條件查詢 3->退出"
getNum=raw_input("選擇:\n")
if getNum=="1":
Sno=raw_input("學號:\n")
print filter(lambda record:record["Sno"]==Sno,self.Stu)[0]
elif getNum=="2":
print "ChineseScore 語文成績;","MathsScore 數學成績;","EnglishScore 英語成績;","ComputerScore 計算機成績;"
print "等於 ==,小於 <, 大於 > ,大於等於 >=,小於等於<= ,不等於!="
print "按如下格式輸入查詢條件 eg: ChineseScore>=60 "
expr=raw_input("條件:\n")
笭工蒂繼酈荒墊維叮哩 Infos=self.__getInfo(expr=expr)
if Infos:
print "共%d記錄"%len(Infos)
for i in Infos:
print i
else:
print "記錄為空"
elif getNum=="3":
break
else:
pass
def __getInfo(self,Sno=None,expr=""):
"""查詢數據
根據學號 _getInfo("111111")
根據分數 _getInfo("EnglishSorce>80")"""
if Sno:
return filter(lambda record:record["Sno"]==Sno,self.Stu)[0]
for operate in [">=",">","<=","<","==","!="]:
if operate in expr:
gradeName,value=expr.split(operate)
return filter(lambda record: eval( repr(record[gradeName.strip()])+operate+value.strip()) ,self.Stu)
return {}

def _showAll(self):
"""顯示所有記錄"""
for i in self.Stu:
print i

@staticmethod
def test():
"""測試"""
_StuInfo=StuInfo()
while True:
print "1->錄入數據 2->修改數據 3->刪除數據 4->查詢數據 5->查看數據 6->退出"
t=raw_input("選擇:\n")
if t=="1":
print "錄入數據"
_StuInfo._add()
elif t=="2":
print "修改數據"
_StuInfo._update()
elif t=="3":
print "刪除數據"
_StuInfo._del()
elif t=="4":
print "查詢數據"
_StuInfo._getInfo()
elif t=="5":
print "顯示所有記錄"
_StuInfo._showAll()
elif t=="6":
break
else:
pass
if __name__=="__main__":
StuInfo.test()

熱點內容
安卓版模擬器哪個好 發布:2024-12-12 16:32:32 瀏覽:118
r星伺服器怎麼這么辣雞 發布:2024-12-12 16:03:15 瀏覽:213
全球第三大存儲 發布:2024-12-12 15:23:41 瀏覽:108
遺傳演算法的pid 發布:2024-12-12 15:15:45 瀏覽:976
都字幕組解壓 發布:2024-12-12 14:48:21 瀏覽:74
陰陽師刷副本腳本 發布:2024-12-12 14:23:50 瀏覽:914
槍之榮耀安卓版在哪裡下載 發布:2024-12-12 14:22:28 瀏覽:520
dota2linux 發布:2024-12-12 14:18:52 瀏覽:482
mysql資料庫如何導入 發布:2024-12-12 14:11:14 瀏覽:921
監控器存儲卡在哪裡看 發布:2024-12-12 14:04:55 瀏覽:269