You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

stu_info = []
def print_menu():
print('学生管理系统')
print('1.添加学员')
print('2.删除学员')
print('3.修改学员信息')
print('4.查询学员信息')
print('5.显示所有学员信息')
print('6.保存学员信息')
print('7.退出系统')
#1.添加
def add_stu_info():
name = input('请输入新学生的姓名:')
sex = input('请输入新学生的性别:')
phone = input('请输入新学生的手机号码:')
new_info = dict() # 定义一个字典
new_info['name'] = name
new_info['sex'] = sex
new_info['phone'] = phone
stu_info.append(new_info)
#2.删除
def del_stu_info(student):
if len(student) != 0:
del_num = int(input('请输入要删除的序号:')) - 1
if del_num < len(stu_info):
del student[del_num]
print(f'删除指定序号:{del_num + 1}成功')
else:
print('要删除的序号有误')
else:
print('学生信息表为空')
#3.修改
def rev_stu_info():
if len(stu_info) != 0:
rev_num = int(input('请输入要修改学生的序号:')) - 1
if rev_num >= len(stu_info):
print("要修改的序号有误")
else:
rev_name = input('请输入要修改学生的姓名:')
rev_sex = input('请输入要修改学生的性别:')
rev_phone = input('请输入要修改学生的手机:')
stu_info[rev_num]['name'] = rev_name
stu_info[rev_num]['sex'] = rev_sex
stu_info[rev_num]['phone'] = rev_phone
else:
print('学生信息表为空')
#4.查询
def que_stu_info():
if len(stu_info) != 0:
que_num = int(input('请输入要查询学生的序号:')) - 1
if que_num >= len(stu_info):
print("要查询的序号有误")
else:
print('学生的信息如下:')
print('序号 姓名 性别 手机号码')
print("%s %s %s" % (temp_info['name'], temp_info['sex'], temp_info['phone']))
else:
print('该学生信息为空')
#5.显示所有学员信息
def show_stu_info():
if len(stu_info) != 0:
print('学生的信息如下:')
print('=' * 30)
print('序号 姓名 性别 手机号码')
i = 1
for temp_info in stu_info:
print("%d %s %s %s" % (i, temp_info['name'], temp_info['sex'], temp_info['phone']))
i += 1
else:
print('学生信息表为空')
def main():
while True:
print_menu()
key = input('请输入对应的功能的数字:')
if key == '1':# 添加
add_stu_info()
elif key == '2':# 删除
del_stu_info(stu_info)
elif key == '3':# 修改
rev_stu_info()
elif key == '4':# 查询
que_stu_info()
elif key == '5':# 显示所有学生信息
show_stu_info()
elif key == '7':# 退出系统
quit_confirm = input('是否要退出系统Yes/No')
if quit_confirm == 'Yes' or quit_confirm == 'yes' or quit_confirm == 'YES':
break
elif quit_confirm == 'No' or quit_confirm == 'no' or quit_confirm == 'NO':
continue
else:
print('输入有误,请重新输入')
else:
print('输入有误,请重新输入')
if __name__ == '__main__':
main()