students = [] # 用于存储学生信息的列表
def add_student():
name = input("请输入学生姓名:")
age = int(input("请输入学生年龄:"))
grade = input("请输入学生年级:")
student = {"姓名": name, "年龄": age, "年级": grade}
students.append(student)
print("学生信息已成功录入!")
def display_students():
for student in students:
print("姓名:", student["姓名"])
print("年龄:", student["年龄"])
print("年级:", student["年级"])
print("-------------")
def sort_students():
sorted_students = sorted(students, key=lambda s: s["姓名"]) # 按姓名排序
for student in sorted_students:
print("姓名:", student["姓名"])
print("年龄:", student["年龄"])
print("年级:", student["年级"])
print("-------------")
def insert_student():
index = int(input("请输入插入的位置:"))
name = input("请输入学生姓名:")
age = int(input("请输入学生年龄:"))
grade = input("请输入学生年级:")
student = {"姓名": name, "年龄": age, "年级": grade}
students.insert(index, student)
print("学生信息已成功插入!")
def delete_student():
index = int(input("请输入要删除的学生索引:"))
if index >= 0 and index < len(students):
del students[index]
print("学生信息已成功删除!")
else:
print("无效的索引!")
def search_student():
name = input("请输入要查找的学生姓名:")
found = False
for student in students:
if student["姓名"] == name:
print("找到了学生信息:")
print("姓名:", student["姓名"])
print("年龄:", student["年龄"])
print("年级:", student["年级"])
found = True
break
if not found:
print("未找到该学生的信息!")
while True:
print("欢迎使用学生管理系统")
print("1.录入单个学生信息")
print("2.显示所有学生信息")
print("3.排序显示所有学生信息")
print("4.插入单个学生信息")
print("5.删除单个学生信息")
print("6.查找单个学生信息")
print("7.退出系统")
choice = input("请输入您的选择:")
if choice == "1":
add_student()
elif choice == "2":
display_students()
elif choice == "3":
sort_students()
elif choice == "4":
insert_student()
elif choice == "5":
delete_student()
elif choice == "6":
search_student()
elif choice == "7":
print("感谢使用学生管理系统!再见!")
break
else:
print("无效的选择,请重新输入!")
基于linux系统的学生管理系统
最新推荐文章于 2024-04-16 19:41:53 发布