用Python语言制作一个学生管理程序
时间: 2024-03-14 11:48:16 浏览: 17
好的,学生管理程序可以包括以下功能:
1. 添加学生信息
2. 查询学生信息
3. 修改学生信息
4. 删除学生信息
5. 显示所有学生信息
下面是一个简单的学生管理程序的实现:
```python
students = [] # 存放学生信息的列表
# 添加学生信息
def add_student():
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
gender = input("请输入学生性别:")
student = {"name": name, "age": age, "gender": gender}
students.append(student)
print("添加成功!")
# 查询学生信息
def query_student():
name = input("请输入要查询的学生姓名:")
for student in students:
if student["name"] == name:
print(f"姓名:{student['name']},年龄:{student['age']},性别:{student['gender']}")
break
else:
print(f"没有找到姓名为{name}的学生!")
# 修改学生信息
def modify_student():
name = input("请输入要修改的学生姓名:")
for student in students:
if student["name"] == name:
new_name = input("请输入新的姓名:")
new_age = input("请输入新的年龄:")
new_gender = input("请输入新的性别:")
student["name"] = new_name
student["age"] = new_age
student["gender"] = new_gender
print("修改成功!")
break
else:
print(f"没有找到姓名为{name}的学生!")
# 删除学生信息
def delete_student():
name = input("请输入要删除的学生姓名:")
for student in students:
if student["name"] == name:
students.remove(student)
print("删除成功!")
break
else:
print(f"没有找到姓名为{name}的学生!")
# 显示所有学生信息
def show_students():
print("姓名\t年龄\t性别")
for student in students:
print(f"{student['name']}\t{student['age']}\t{student['gender']}")
# 主函数
def main():
while True:
print("""
1. 添加学生信息
2. 查询学生信息
3. 修改学生信息
4. 删除学生信息
5. 显示所有学生信息
0. 退出程序
""")
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("请输入正确的操作选项!")
if __name__ == "__main__":
main()
```
这个学生管理程序使用了一个列表来存放学生信息,通过不同的函数实现了添加、查询、修改、删除和显示学生信息的功能。您可以根据自己的需求对程序进行修改和扩展。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![.zip](https://img-home.csdnimg.cn/images/20210720083646.png)