xsxt = [{'num': '2020021321', 'name': '王', 'xb': '男', 'age': '19', 'yw': 78, 'sx': 88, 'yy': 87, 'score': 253},
{'num': '2020021222', 'name': '邓', 'xb': '男', 'age': '18', 'yw': 88, 'sx': 100, 'yy': 87, 'score': 275}]
zhanghao = ('123', '548659')
mima = ('56', '787878')
def denglu(): # 登录界面
print('=' * 20)
print('1.登录')
print('2.退出')
print('=' * 20)
def zm(): # 账号密码控制
count = 0
while count < 3:
a = input('请输入账号')
b = input('请输入密码')
if a == zhanghao[0] and b == mima[0]:
print('登录成功')
xunhan()
return
elif a == zhanghao[1] and b == mima[1]:
print('登录成功')
xunhan()
return
else:
print('密码错误机会三次')
count += 1
def xt(): # 系统界面
print("=" * 30)
print('学生管理系统V1.0')
print('1.添加学生信息')
print('2.删除学生信息')
print('3.修改学生信息')
print('4.显示所有学生信息')
print('5.查找学生信息')
print('6.排序')
print('0.退出系统')
print("=" * 30)
def zj(): # 添加
name = input('输入姓名')
while (True):
xb = input('输入性别 男/女')
if not xb == '男' and not xb == '女':
print('请输入正确性别')
else:
break
num = input('输入学号')
age = input('输入年龄')
while (True):
yw = float(input('输入语文成绩'))
if 0 <= yw <= 100:
break
else:
print('请输入0——100之内的数')
while (True):
sx = float(input('输入数学成绩'))
if 0 <= sx <= 100:
break
else:
print('请输入0——100之内的数')
while (True):
yy = float(input('输入英语成绩'))
if 0 <= yy <= 100:
break
else:
print('请输入0——100之内的数')
newxs = {}
newxs['num'] = num
newxs['name'] = name
newxs['xb'] = xb
newxs['age'] = age
newxs['yw'] = yw
newxs['sx'] = sx
newxs['yy'] = yy
newxs["score"] = newxs["yw"] + newxs["sx"] + newxs["yy"]
xsxt.append(newxs)
def sc(): # 删除
e = input('请输入要删除的学生的学号')
for i in xsxt:
if i['num'] == e:
xsxt.remove(i)
print('删除成功')
else:
print('删除失败返回菜单')
xunhan()
def xians(): # 显示信息
for i in xsxt:
print("学号:", i['num'], '姓名:', i['name'], '性别:', i['xb'], '年龄:', i['age'], '语文成绩:', i['yw'], "数学成绩:", i['sx'],
"英语成绩:", i['yy'], "总成绩:", i['score'])
def xg(): # 修改
stu_num = input("请输入要修改的学生的学号:")
b = 0
c = len(xsxt)
for i in xsxt:
if i["num"] == stu_num:
while True:
new_num = input("请输入该学生修改后的学号:")
a = 0
for n in xsxt:
if n["num"] == new_num:
a += 1
if a >= 1:
print("输入的学号与其他同学重复,请重新输入:")
else:
i["num"] = new_num
print("修改成功")
z = 0
break
new_name = input("请输入该学生修改后的姓名:")
i["name"] = new_name
print("修改成功")
new_xb = input("请输入该学生修改后的性别:")
i["xb"] = new_xb
print("修改成功")
new_age = input("请输入该学生修改后的年龄:")
i["age"] = new_age
print("修改成功")
while (True):
new_yw = float(input("请输入该学生修改后的语文成绩:"))
if 0 <= new_yw <= 100:
i["yw"] = new_yw
print("修改成功")
z = 0
break
else:
print("成绩输入错误,请重新输入0-100以内的正确成绩。")
while (True):
new_sx = float(input("请输入该学生修改后的数学成绩:"))
if 0 <= new_sx <= 100:
i["sx"] = new_sx
print("修改成功")
z = 0
break
else:
print("成绩输入错误,请重新输入0-100以内的正确成绩。")
while (True):
new_yy = float(input("请输入该学生修改后的英语成绩:"))
if 0 <= new_yy <= 100:
i["yy"] = new_yy
print("修改成功")
z = 0
break
else:
print("成绩输入错误,请重新输入0-100以内的正确成绩。")
i["score"] = i["yw"] + i["sx"] + i["yy"]
else:
b += 1
if b == c:
print("输入的学生不存在,请输入正确的学生学号。")
xg()
def cz(): # 查询
b = 0
c = len(xsxt)
a = input('确认按1,返回按其他')
if a == '1':
d = input("请输入需要查找的学生的学号:")
for i in xsxt:
if i['num'] == d:
print("学号:", i['num'], '姓名:', i['name'], '性别:', i['xb'], '年龄:', i['age'], '语文成绩:', i['yw'], "数学成绩:",
i['sx'], "英语成绩:", i['yy'], "总成绩:", i['score'])
else:
b += 1
if b == c:
print("未查找到该名学生的信息")
else:
xunhan()
def xunhan(): # 主程序循环
while (True):
xt()
def kong():
c = input("请输入序号")
return int(c)
c = kong()
if c == 0:
break
elif c == 1:
zj()
elif c == 2:
sc()
elif c == 3:
xg()
elif c == 4:
xians()
elif c == 5:
cz()
elif c == 6:
pxxunhan()
continue
def px1(): # 排序界面
print("=" * 15)
print('1.按总分成绩排序')
print('2.按语文成绩排序')
print('3.按数学成绩排序')
print('4.按英语成绩排序')
print('按其他退出')
print('=' * 15)
def pxxunhan(): # 排序控制
px1()
while True:
def kong2():
t = input("请输入序号")
return int(t)
t = kong2()
if t == 1:
zfpx()
elif t == 2:
ywpx()
elif t == 3:
sxpx()
elif t == 4:
yypx()
else:
break
def zfpx():
sort_list = sorted(xsxt, key=lambda x: x['score'], reverse=True)
del xsxt[:]
xsxt.extend(sort_list)
print("排序成功")
xians()
def ywpx():
sort_list = sorted(xsxt, key=lambda x: x['yw'], reverse=True)
del xsxt[:]
xsxt.extend(sort_list)
print("排序成功")
xians()
def sxpx():
sort_list = sorted(xsxt, key=lambda x: x['sx'], reverse=True)
del xsxt[:]
xsxt.extend(sort_list)
print("排序成功")
xians()
def yypx():
sort_list = sorted(xsxt, key=lambda x: x['yy'], reverse=True)
del xsxt[:]
xsxt.extend(xsxt)
print("排序成功")
xians()
while True: # 登录界面控制
denglu()
def kong1():
b = input('请输入序号')
return int(b)
b = kong1()
if b == 1:
zm()
elif b == 2:
break
本人的练习很基础的增删改查
2022.12.16修复删除功能