def print_menu():
print('=' * 30)
print('学生管理系统')
print('1.添加学生信息')
print('2.删除学生信息')
print('3.修改学生信息')
print('4.显示所有学生信息')
print('0.退出系统')
print('=' * 30)
stu_info = []
def add_stu_info():
new_name = input('请输入新学生的姓名:')
new_sex = input('请输入新学生的性别:')
new_phone = input('请输入学生的手机号码:')
new_info = dict()
new_info['name'] = new_name
new_info['sex'] = new_sex
new_info['phone'] = new_phone
stu_info.append(new_info)
def del_stu_info(student):
del_num = int(input('请输入要删除的序号:')) - 1
del student[del_num]
def modify_stu_info():
if len(stu_info) != 0:
stu_id = int(input('请输入学生序号:'))
new_name = input('请输入学生姓名:')
new_sex = input('请输入学生性别(男/女):')
new_phone = input('请输入学生的手机号码:')
stu_info[stu_id - 1]['name'] = new_name
stu_info[stu_id - 1]['sex'] = new_sex
stu_info[stu_id - 1]['phone'] = new_phone
else:
print('学生信息表为空')
def show_stu_info():
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
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':
modify_stu_info()
elif key == '4':
show_stu_info()
elif key == '0':
quit_confirm = input('亲,真的要退出么?(Yes or No):')
if quit_confirm == 'Yes':
break
else:
print('输入有误,请重新输入')
if __name__ == '__main__':
main()
学生管理系统 python
最新推荐文章于 2023-08-14 22:20:00 发布