程序做一个简易学生管理系统包含添加学生删除学生修改学生等功能
时间: 2024-02-25 16:51:57 浏览: 37
好的,我可以为您编写一个简易的学生管理系统,包含添加学生、删除学生、修改学生等功能。以下是示例代码:
```python
students = {} # 学生信息以字典形式存储,key为学生姓名,value为学生信息字典
# 添加学生
def add_student(name, age, gender):
if name in students:
print("该学生已存在")
else:
students[name] = {'age': age, 'gender': gender}
print("添加成功")
# 删除学生
def delete_student(name):
if name in students:
students.pop(name)
print("删除成功")
else:
print("该学生不存在")
# 修改学生信息
def modify_student(name, age=None, gender=None):
if name in students:
if age:
students[name]['age'] = age
if gender:
students[name]['gender'] = gender
print("修改成功")
else:
print("该学生不存在")
# 查询学生信息
def query_student(name):
if name in students:
info = students[name]
print(f"姓名:{name},年龄:{info['age']},性别:{info['gender']}")
else:
print("该学生不存在")
```
您可以根据需要调用上述函数,例如:
```python
add_student('张三', 18, '男')
add_student('李四', 20, '女')
delete_student('张三')
modify_student('李四', gender='男')
query_student('李四')
```
希望可以帮助到您。如果有任何问题,请随时提出。
相关推荐
![](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)