yongpython列表写一个学生信息管理,学生信息包括学号,姓名,性别,语文,数学,英语成绩,包含有
时间: 2023-05-29 13:05:44 浏览: 92
以下功能:
1. 添加学生信息
2. 删除学生信息
3. 修改学生信息
4. 查询学生信息
5. 显示所有学生信息
6. 退出系统
代码如下:
```python
# 定义一个空列表,用于存储学生信息
students = []
while True:
# 显示菜单
print("="*30)
print("学生信息管理系统")
print("1. 添加学生信息")
print("2. 删除学生信息")
print("3. 修改学生信息")
print("4. 查询学生信息")
print("5. 显示所有学生信息")
print("6. 退出系统")
print("="*30)
# 获取用户输入
choice = input("请输入操作编号:")
# 添加学生信息
if choice == "1":
stu_id = input("请输入学号:")
name = input("请输入姓名:")
gender = input("请输入性别:")
chinese = int(input("请输入语文成绩:"))
math = int(input("请输入数学成绩:"))
english = int(input("请输入英语成绩:"))
# 将学生信息添加到列表中
students.append({"id": stu_id, "name": name, "gender": gender,
"chinese": chinese, "math": math, "english": english})
print("添加成功!")
# 删除学生信息
elif choice == "2":
stu_id = input("请输入要删除的学生学号:")
for stu in students:
if stu["id"] == stu_id:
students.remove(stu)
print("删除成功!")
break
else:
print("未找到该学生信息!")
# 修改学生信息
elif choice == "3":
stu_id = input("请输入要修改的学生学号:")
for stu in students:
if stu["id"] == stu_id:
print("1. 修改姓名")
print("2. 修改性别")
print("3. 修改语文成绩")
print("4. 修改数学成绩")
print("5. 修改英语成绩")
sub_choice = input("请输入要修改的信息编号:")
if sub_choice == "1":
stu["name"] = input("请输入新的姓名:")
elif sub_choice == "2":
stu["gender"] = input("请输入新的性别:")
elif sub_choice == "3":
stu["chinese"] = int(input("请输入新的语文成绩:"))
elif sub_choice == "4":
stu["math"] = int(input("请输入新的数学成绩:"))
elif sub_choice == "5":
stu["english"] = int(input("请输入新的英语成绩:"))
else:
print("输入有误!")
print("修改成功!")
break
else:
print("未找到该学生信息!")
# 查询学生信息
elif choice == "4":
stu_id = input("请输入要查询的学生学号:")
for stu in students:
if stu["id"] == stu_id:
print("学号\t姓名\t性别\t语文\t数学\t英语")
print("{}\t{}\t{}\t{}\t{}\t{}".format(stu["id"], stu["name"], stu["gender"],
stu["chinese"], stu["math"], stu["english"]))
break
else:
print("未找到该学生信息!")
# 显示所有学生信息
elif choice == "5":
print("学号\t姓名\t性别\t语文\t数学\t英语")
for stu in students:
print("{}\t{}\t{}\t{}\t{}\t{}".format(stu["id"], stu["name"], stu["gender"],
stu["chinese"], stu["math"], stu["english"]))
# 退出系统
elif choice == "6":
print("感谢使用学生信息管理系统!")
break
# 输入有误
else:
print("输入有误,请重新输入!")
```
运行程序,即可使用学生信息管理系统。
相关推荐
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![py](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)