student1=[
{1:'lucy','age':17,'sex':'n','Pnum':1111111},
{2:'tom','age':17,'sex':'m','Pnum':2222222},
{3:'jack','age':17,'sex':'m','Pnum':3333333}]
def menu():
print("-"*15)
print("学生管理系统")
print("1.输入学号查询学生信息")
print("2.添加学生信息")
print("3.删除学生信息")
print("4.显示学生信息")
print("5.修改学生信息")
print("6.退出")
print("-"*15)
def lookup():
sid=int(input("输入查询学号;")-1)
if sid>len(student1)-1:
print("输入错误,返回菜单")
else:
print(student1[sid])
input("按回车键继续")
def append():
newsid=eval(input('输入新同学的学号:'))
newName=eval(input('输入新同学的姓名:'))
newage=eval(input('输入新同学的年龄:'))
newSex=eval(input('输入新同学的性别:'))
newPnum=eval(input('输入新同学的手机号:'))
newstudent1={ }
newstudent1[newsid]=newName
newstudent1['age']=newage
newstudent1['sex']=newSex
newstudent1['Pnum']=newPnum
student1.append(newstudent1)
input("按回车键继续")
def delete():
did=int(input("输入要删除的学号:"))-1
del student1[did]
input("按回车键继续")
def all():
print("所有信息如下:")
i=1
for show in student1:
print("{}".format(show))
i+=1
input("按回车键继续")
def revise():
resid=int(input("输入要修改的学生学号:"))-1
r=input("要修改的对象:")
if r=='1':
newage=input("修改后的年龄")
student1[resid]['age']=newage
elif r=='2':
newPnum=input("修改后的手机号")
student1[resid]['Pnum']=newPnum
else:
newage = input("修改后的年龄")
newPnum = input("修改后的手机号")
student1[resid]['age'] = newage
student1[resid]['Pnum'] = newPnum
input("按回车键继续")
def main():
while True:
menu()
key=input("输入选项数字:")
if key=='1':
lookup()
elif key=='2':
append()
elif key=='3':
delete()
elif key=='4':
all()
elif key=='5':
revise()
elif key=='6':
print("是否退出?")
exit=input("输入y退出:")
if exit=='y':
break
else:
print("输入错误,返回")
main()
04-08
11万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)