用python创建学生信息管理系统、 #输入不同功能数字,响应相应功能 #1:录入学生信息(学号(id),姓名,,年龄,性别) #2:显示所有学生信息 #3:显示指定学生信息 #4:删除指定学生信息 #5:退出系统
时间: 2024-04-08 18:29:35 浏览: 34
以下是一个简单的学生信息管理系统的Python代码示例:
```python
students = []
def add_student():
student = {}
student['id'] = input("请输入学号: ")
student['name'] = input("请输入姓名: ")
student['age'] = input("请输入年龄: ")
student['gender'] = input("请输入性别: ")
students.append(student)
print("信息录入成功!")
def show_all_students():
if len(students) == 0:
print("当前没有学生信息!")
else:
for student in students:
print("学号:", student['id'])
print("姓名:", student['name'])
print("年龄:", student['age'])
print("性别:", student['gender'])
print("--------------------")
def show_student():
student_id = input("请输入要查询的学生学号: ")
found = False
for student in students:
if student['id'] == student_id:
print("学号:", student['id'])
print("姓名:", student['name'])
print("年龄:", student['age'])
print("性别:", student['gender'])
found = True
break
if not found:
print("未找到该学生信息!")
def delete_student():
student_id = input("请输入要删除的学生学号: ")
found = False
for student in students:
if student['id'] == student_id:
students.remove(student)
print("删除成功!")
found = True
break
if not found:
print("未找到该学生信息!")
while True:
print("学生信息管理系统")
print("1. 录入学生信息")
print("2. 显示所有学生信息")
print("3. 显示指定学生信息")
print("4. 删除指定学生信息")
print("5. 退出系统")
choice = input("请选择功能(输入对应数字): ")
if choice == '1':
add_student()
elif choice == '2':
show_all_students()
elif choice == '3':
show_student()
elif choice == '4':
delete_student()
elif choice == '5':
print("已退出系统!")
break
else:
print("无效的输入,请重新选择!")
```
运行该程序后,根据提示输入对应的数字即可执行相应的功能。
阅读全文