class Student(object):
# 建立學(xué)生信息儲(chǔ)存的列表(嵌套的方式)
studentInformation = []
# 對(duì)學(xué)生對(duì)象的數(shù)據(jù)進(jìn)行說(shuō)明
studentShow = ["學(xué)號(hào):", "姓名:", "年齡:"]
# 錄入學(xué)生
def addstudent(self):
sno = input("請(qǐng)輸入學(xué)號(hào):")
name = input("請(qǐng)輸入姓名:")
sage = input("請(qǐng)輸入年齡:")
# 建立一個(gè)列表,用于暫時(shí)存儲(chǔ)
student = [sno, name, sage]
# 加入學(xué)生(判斷學(xué)號(hào)是否重復(fù))
x = 0
# 剛開(kāi)始錄入學(xué)生時(shí),學(xué)號(hào)不可能重復(fù)
if len(self.studentInformation) == 0:
self.studentInformation.append(student)
# 判斷重復(fù)
else:
while x len(self.studentInformation):
if self.studentInformation[x][0] != sno:
x += 1
else:
print("學(xué)號(hào)重復(fù)?。?!\n請(qǐng)重新輸入序號(hào)?。?!")
break
else:
self.studentInformation.append(student)
print("加入成功?。?!")
# 輸出學(xué)生
def showstudent(self):
print("學(xué)生信息輸出如下:")
for i in range(len(self.studentInformation)):
print(self.studentShow[0]+self.studentInformation[i][0], end=" ")
print(self.studentShow[1] + self.studentInformation[i][1], end=" ")
print(self.studentShow[2] + self.studentInformation[i][2])
# 刪除學(xué)生
def deletestudent(self):
x = 0
sno = input("請(qǐng)輸入學(xué)生學(xué)號(hào):")
while x len(self.studentInformation):
if self.studentInformation[x][0] == sno:
del self.studentInformation[x]
print("刪除學(xué)生成功!!!")
break
else:
x += 1
else:
print("不存在當(dāng)前學(xué)生!??!")
# 查詢學(xué)生
def selectstudent(self):
x = 0
sno = input("請(qǐng)輸入查詢學(xué)生的學(xué)號(hào)")
while x len(self.studentInformation):
if self.studentInformation[x][0] == sno:
print(self.studentShow[0] + self.studentInformation[x][0], end=" ")
print(self.studentShow[1] + self.studentInformation[x][1], end=" ")
print(self.studentShow[2] + self.studentInformation[x][2])
break
else:
x += 1
else:
print("未查詢到當(dāng)前學(xué)生!?。?)
# 修改學(xué)生
def changestudent(self):
x = 0
sno = input("請(qǐng)輸入修改學(xué)生的學(xué)號(hào):")
while x len(self.studentInformation):
if self.studentInformation[x][0] == sno:
name = input("請(qǐng)輸入修改后的姓名:")
sage = input("請(qǐng)輸入修改后的年齡:")
self.studentInformation[x][1] = name
self.studentInformation[x][2] = sage
print("修改成功!!!")
break
else:
x += 1
# 界面打印
@staticmethod
def printui():
print("輸入:0 --退出程序--")
print("輸入:1 --錄入學(xué)生--")
print("輸入:2 --輸出學(xué)生--")
print("輸入:3 --刪除學(xué)生--")
print("輸入:4 --查詢學(xué)生--")
print("輸入:5 --修改學(xué)生--")
# 程序調(diào)用
def run(self):
self.printui()
number = input("請(qǐng)輸入功能前面的代碼:")
# 無(wú)限循環(huán)
var = 1
while var == 1:
if int(number) == 1:
self.addstudent()
self.printui()
number = input("請(qǐng)輸入功能前面的代碼:")
elif int(number) == 2:
self.showstudent()
self.printui()
number = input("請(qǐng)輸入功能前面的代碼:")
elif int(number) == 3:
self.deletestudent()
self.printui()
number = input("請(qǐng)輸入功能前面的代碼:")
elif int(number) == 4:
self.selectstudent()
self.printui()
number = input("請(qǐng)輸入功能前面的代碼:")
elif int(number) == 5:
self.changestudent()
self.printui()
number = input("請(qǐng)輸入功能前面的代碼:")
elif int(number) == 0:
break
else:
print("您輸入的序號(hào)不對(duì)!\n請(qǐng)重新輸入!")
self.printui()
number = input("請(qǐng)輸入功能前面的代碼:")
else:
print("再見(jiàn)!")
exit()