学生录入练习
2021-12-16 本文已影响0人
lajunta
# -*- coding: utf-8 -*-
students = []
choice = 0
def menu():
print("""
1 - 录入学生
2 - 查询学生
3 - 删除学生
4 - 列出所有学生
0 - 退出
""")
global choice
choice = int(input("请选择: "))
def luru():
student = {}
student["name"] = input("输入学生的姓名")
student["xuehao"] = input("输入学生的学号")
students.append(student)
print("成功添加学生")
def showall():
for st in students:
print(st)
def chaxun():
xh = input("请输入学生学号: ")
find = False
for st in students:
if st["xuehao"] == xh:
print(f"学生姓名: {st.get('name')},学号: {st['xuehao']}")
find = True
break
if not find:
print("没有找到")
def shanchu():
find = False
xh = input("请输入学号: ")
for st in students:
if st["xuehao"] == xh:
find = True
students.remove(st)
if find:
print("已经删除")
else:
print("没有找到学生")
menu()
while choice !=0:
if choice == 1:
luru()
elif choice == 2:
chaxun()
elif choice == 3:
shanchu()
elif choice == 4:
showall()
else:
print("输入有问题")
menu()
print("已经退出程序")