student = []
def print_menu():
print("學生管理系統V2.0")
print("=" * 30)
print("1.添加學生基本信息")
print("2.通過學號刪除學生信息")
print("3.顯示全部學生信息")
print("4.通過姓名查找學生的信息")
print("5.通過學號修改學生信息")
print("6.導出學生基本信息到指定路徑的文件中")
print("7.查詢成績最高的學生基本信息")
print("8.查詢成績最低的學生基本信息")
print("9.根據學生綜合成績排序后顯示基本信息")
print("10.根據輸入的綜合成績,統計大于輸入成績的人數")
print("11.計算當前所有學生綜合成績的平均值")
print("12.退出系統")
print("=" * 30)
def add():
xh = input("請輸入學生的學號:")
xm = input("請輸入學生姓名:")
xb = input("請輸入學生性別:(男/女)")
phone = input("請輸入學生的手機號碼:")
score = input("請輸入學生的綜合成績:")
student_infos = {}
student_infos["xuehao"] = xh
student_infos["name"] = xm
student_infos["sex"] = xb
student_infos["phone"] = phone
student_infos["score"] = score
student.append(student_infos)
print(student)
def del_info():
stdId =input("請輸入需要刪除學生的學號:")
z = 0
for temp in student:
if stdId == temp['xuehao']:
indexxuehao = student.index(temp)
z = 1
break
else:
continue
if z ==1:
fina = input ("確認是否刪除?(yes or no):")
if fina == "yes":
del student[indexxuehao]
print("恭喜您已成功刪除該新學生了!")
else:
print("您放棄刪除該學生信息了!")
else:
print("很抱歉,系統不存在該學生信息!")
def display():
print("*" * 30)
print("學生的信息如下:")
print("*" * 30)
print("序號 學號 姓名 性別 手機號碼 綜合成績")
i = 1
for temp in student:
print("%d %s %s %s %s %s" % (
i, temp["xuehao"], temp["name"], temp["sex"], temp["phone"], temp["score"]))
i += 1
def find():
while True:
name = input("請輸入要查找的學生姓名")
for temp in student:
if temp['name'] == name:
print("找到此學生,信息如下:")
print("學號:%s 姓名:%s 性別:%s 手機號碼:%s 綜合成績:%s " % (
temp["xuehao"], temp["name"], temp["sex"], temp["phone"], temp["score"]))
break
else:
print("沒有這個學生")
def change():
print("您選擇了修改學生信息功能")
gai = input("請輸入你要修改學生的學號:")
i = 0
ii = 0
for temp in student:
if temp["xuehao"] == gai:
ii = 1
break
else:
i = i + 1
if ii == 1:
while True:
xiaocaidan = int(input(" 1.修改學號\n 2.修改姓名 \n 3.修改性別 \n 4.修改手機號碼 \n 5.修改綜合成績 \n 6.退出修改 \n"))
if xiaocaidan == 1:
aaa = input("輸入更改后的學號:")
# 修改后的學號要驗證是否唯一
i = 0
ii1 = 0
for temp1 in student:
if temp1["xuehao"] == aaa:
ii1 = 1
break
else:
i = i + 1
if ii1 == 1:
print("輸入學號不可重復,修改失敗!")
else:
temp["xuehao"] = aaa
print("學號已修改")
elif xiaocaidan == 2:
bbb = input("輸入新的姓名:")
temp["name"] = bbb
print("姓名已修改")
elif xiaocaidan == 3:
ccc = input("輸入新的性別(男/女):")
temp["sex"] = ccc
print("性別已修改")
elif xiaocaidan == 4:
ddd = input("輸入新的手機號碼:")
temp["phone"] = ddd
print("手機號碼已修改")
elif xiaocaidan == 5:
eee = input("輸入新的成績:")
temp["score"] = eee
print("綜合成績已修改")
elif xiaocaidan == 6:
break
else:
print("輸入錯誤請重新輸入")
else:
print("學號輸入錯誤,修改失敗!")
def baocun():
file = open("xueshengxinxi.txt", "w")
file.write(str(student))
file.write('\n')
file.close()
def findmax():
studentone = []
for temp in student: # 遍歷字典的成績
studentone.append(temp["score"]) # 將遍歷的成績加入空列表
studentone.sort(reverse=True) # 將列表的值從大到小排序
n = studentone[0]
i = 0
j = 0
for temp in student:
if temp["score"] == n:
j = 1
break
else:
i = i + 1
if j == 0:
print("沒有此學生,查詢失敗!")
else:
print("找到此學生,信息如下:")
print("學號:%s 姓名:%s 性別:%s 手機號碼:%s 綜合成績:%s" % (
temp["xuehao"], temp["name"], temp["sex"], temp["phone"], temp["score"]))
def findmin():
studenttwo = []
for temp in student: # 遍歷字典的成績
studenttwo.append(temp["score"]) # 將遍歷的成績加入空列表
studenttwo.sort() # 將列表的值從小到大排序
n = studenttwo[0]
i = 0
j = 0
for temp in student:
if temp["score"] == n:
j = 1
break
else:
i = i + 1
if j == 0:
print("沒有此學生,查詢失敗!")
else:
print("找到此學生,信息如下:")
print("學號:%s 姓名:%s 性別:%s 手機號碼:%s 綜合成績:%s " % (
temp["xuehao"], temp["name"], temp["sex"], temp["phone"], temp["score"]))
def paixu():
print("從高到低成績排序:")
print("序號 學號 姓名 性別 手機號碼 綜合成績")
studentthree = []
for temp in student: # 遍歷字典的成績
studentthree.append(temp["score"]) # 將遍歷的成績加入空列表
studentthree.sort(reverse=True) # 將列表的值從大到小排序
for n in studentthree:
i = 0
j = 0
for temp in student:
if temp["score"] == n:
j = 1
break
else:
i = i + 1
if j == 0:
print("沒有此學生,查詢失敗!")
else:
print("%d %s %s %s %s %s" % (
i, temp["xuehao"], temp["name"], temp["sex"], temp["phone"], temp["score"]))
def count():
studentfour = []
studentfive = []
for temp in student: # 遍歷字典的成績
studentfour.append(temp["score"]) # 將遍歷的成績加入空列表
a = input("請輸入需要統計人數的成績線(大于該成績的人數):")
i = 0
for temp in studentfour:
if temp[i] >= a:
studentfive.append(temp[i])
else:
pass
i += 1
print("大于該成績的人數有:%s" % (len(studentfive)))
def average():
studentsix = []
for temp in student: # 遍歷字典的成績
studentsix.append(temp["score"]) # 將遍歷的成績加入空列表
studentsix = [int(x) for x in studentsix]
tt = sum(studentsix)
pingjun = tt / len(studentsix)
print(pingjun)
def quit():
while True:
d = input("確定退出嗎?(Yes or No):")
if d == "Yes":
break
else:
print("輸入有誤,請重新輸入")
def last():
while True:
print_menu()
key = input("請輸入功能對應的數字:")
if key == "1":
add()
elif key == "2":
del_info()
elif key == "3":
display()
elif key == "4":
find()
elif key == "5":
change()
elif key == "6":
baocun()
elif key == "7":
findmax()
elif key == "8":
findmin()
elif key == "9":
paixu()
elif key == "10":
count()
elif key == "11":
average()
elif key == "12":
quit()
last()
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

