代码(记得选为最佳答案哦!):def clear():
global info
info = {}
def introduction():
print('请选择功能.....')
print('1.添加学员')
print('2.删除学员')
print('3.修改学员')
print('4.查询学员')
print('5.显示所有学员')
print('6.退出系统')
print('-'*20)
def add():
global info
temp = []
temp2 = input('请输入学号')
if temp2 in info:
print('字典中已有此人')
else:
temp.append('姓名:'+input('请输入姓名'))
temp.append('性别:'+input('请输入性别'))
temp.append('宿舍房间号:'+input('请输入宿舍房间号'))
temp.append('联系电话:'+input('请输入联系电话'))
info[temp2] = temp
def delete():
global info
temp = input('请输入要删除学员的学号')
try:
info.pop(temp)
except KeyError:
print('输入错误!没有学号为'+temp+'的人!')
def modify():
global info
temp = input('请输入要修改学员的学号')
if temp not in info:
print('字典中没有此人')
else:
temp.append(input('请输入姓名'))
temp.append(input('请输入性别'))
temp.append(input('请输入宿舍房间号'))
temp.append(input('请输入联系电话'))
info[temp2] = temp
def search():
global info
temp = input('请输入要搜索学员的学号')
temp2 = info.get(temp,'没有此人!\n')
print('学号:',temp)
for each in temp2:
print(each,end='')
print('\n')
def all():
global info
for each in info:
temp = each
temp2 = info.get(temp,'没有此人!')
print('学号:',temp)
for each in temp2:
print(each,end='')
print('\n')
clear()
while True:
introduction()
i = str(input('请输入功能序号:'))
if i == '1':
add()
elif i == '2':
delete()
elif i == '3':
modify()
elif i == '4':
search()
elif i== '5':
all()
elif i == '6':
break
else:
print('输入功能有误,请重新输入')
|