python学生信息管理系统,包含学号,姓名,性别,生日,电话。并对此进行增加,查询,修改,删除的操作
时间: 2023-12-15 08:04:07 浏览: 55
好的,我可以帮你实现这个学生信息管理系统。首先,我们可以使用 Python 的字典来存储每个学生的信息,其中学号作为字典的键,其他信息作为字典的值。具体的实现代码如下:
```python
students = {}
def add_student():
"""添加学生信息"""
stu_no = input("请输入学号:")
name = input("请输入姓名:")
gender = input("请输入性别:")
birthday = input("请输入生日:")
phone = input("请输入电话:")
student = {'姓名': name, '性别': gender, '生日': birthday, '电话': phone}
students[stu_no] = student
print("添加成功!")
def search_student():
"""查询学生信息"""
stu_no = input("请输入要查询的学号:")
if stu_no in students:
student = students[stu_no]
print("学号:", stu_no)
for key, value in student.items():
print(key, ":", value)
else:
print("该学生不存在!")
def modify_student():
"""修改学生信息"""
stu_no = input("请输入要修改的学号:")
if stu_no in students:
student = students[stu_no]
print("学号:", stu_no)
for key, value in student.items():
print(key, ":", value)
name = input("请输入姓名:")
gender = input("请输入性别:")
birthday = input("请输入生日:")
phone = input("请输入电话:")
student['姓名'] = name
student['性别'] = gender
student['生日'] = birthday
student['电话'] = phone
students[stu_no] = student
print("修改成功!")
else:
print("该学生不存在!")
def delete_student():
"""删除学生信息"""
stu_no = input("请输入要删除的学号:")
if stu_no in students:
del students[stu_no]
print("删除成功!")
else:
print("该学生不存在!")
def show_menu():
"""显示菜单"""
print("===== 学生信息管理系统 =====")
print("1. 添加学生信息")
print("2. 查询学生信息")
print("3. 修改学生信息")
print("4. 删除学生信息")
print("0. 退出系统")
print("=" * 25)
def main():
"""主函数"""
while True:
show_menu()
choice = input("请输入要执行的操作:")
if choice == '1':
add_student()
elif choice == '2':
search_student()
elif choice == '3':
modify_student()
elif choice == '4':
delete_student()
elif choice == '0':
print("谢谢使用!")
break
else:
print("输入有误,请重新输入!")
if __name__ == '__main__':
main()
```
在这个程序中,我们定义了 `students` 变量来存储所有学生的信息,然后定义了四个函数来实现增加、查询、修改和删除学生信息的操作。最后,我们定义了一个 `main` 函数来显示菜单,并根据用户的选择来调用相应的函数。运行程序后,就可以使用菜单来进行各种操作了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.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)
![](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)