python实训学生管理系统
时间: 2023-12-10 13:35:58 浏览: 130
以下是一个简单的Python实训学生管理系统的例子:
```python
# 定义一个空的学生列表
students = []
# 添加学生信息
def add_student():
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
gender = input("请输入学生性别:")
student = (name, age, gender)
students.append(student)
print("添加成功!")
# 查询学生信息
def query_student():
name = input("请输入要查询的学生姓名:")
for student in students:
if student[0] == name:
print("姓名:{},年龄:{},性别:{}".format(student[0], student[1], student[2]))
break
else:
print("未找到该学生!")
# 修改学生信息
def modify_student():
name = input("请输入要修改的学生姓名:")
for student in students:
if student[0] == name:
age = input("请输入学生年龄:")
gender = input("请输入学生性别:")
student = (name, age, gender)
index = students.index(student)
students[index] = student
print("修改成功!")
break
else:
print("未找到该学生!")
# 删除学生信息
def delete_student():
name = input("请输入要删除的学生姓名:")
for student in students:
if student[0] == name:
students.remove(student)
print("删除成功!")
break
else:
print("未找到该学生!")
# 显示学生信息
def show_students():
print("学生信息如下:")
for student in students:
print("姓名:{},年龄:{},性别:{}".format(student[0], student[1], student[2]))
# 主菜单
def main_menu():
print("欢迎使用学生管理系统!")
print("1.添加学生信息")
print("2.查询学生信息")
print("3.修改学生信息")
print("4.删除学生信息")
print("5.显示学生信息")
print("0.退出系统")
# 运行程序
while True:
main_menu()
choice = input("请输入您的选择:")
if choice == '1':
add_student()
elif choice == '2':
query_student()
elif choice == '3':
modify_student()
elif choice == '4':
delete_student()
elif choice == '5':
show_students()
elif choice == '0':
print("谢谢使用,再见!")
break
else:
print("输入有误,请重新输入!")
```
阅读全文