定义学生班级信息 class_info = [] def print_menu(): print("---------------------------") print(" 学生管理系统 V1.0") print(" 1:添加学生") print(" 2:删除学生") print(" 3:修改学生") print(" 4:查询学生") print(" 5:显示所有学生") print(" 6:退出系统") print("---------------------------") def add_student(): # 声明使用全局变量 class_info global class_info # 输入学生信息 name = input("请输入添加学生的姓名: >>>") age = int(input("请输入添加学生的年龄: >>>")) score = int(input("请输入添加学生的成绩: >>>")) # 判断输入信息 for student in class_info: if student["name"] == name: print("您输入的学生已经存在!") return -1 if 0 >= age: print("您输入的年龄有误!") return -2 if 0 > score or score > 101: print("您输入的成绩有误!") return -3 # 描述学生信息 student = { "name": name, "age": age, "score": score } # 将学生信息添加到班级信息中 class_info.append(student) print("恭喜您,添加成功") return 0 def del_student(): # 声明使用全局变量class_info global class_info # 输入需要删除的学生姓名 name = input("请输入需要删除的学生姓名: >>>") # 寻找学生 for student in class_info: if student["name"] == name: # 找到需要删除的学生 class_info.remove(student) print("删除成功!") return 0 print("您输入的学生不存在") return -1 def main(): while True: # 打印菜单 print_menu() # 输入自己的选择 choose = int(input("请输入您的选择: >>>")) if choose == 1: add_student() print(class_info) elif choose == 2: del_student() print(class_info) pass main()帮我继续完成学生管理系统,完成其功能
时间: 2024-02-28 18:52:46 浏览: 27
好的,以下是完整的学生管理系统代码,已经实现了添加、删除、修改、查询和显示所有学生的功能:
```python
class_info = []
def print_menu():
print("---------------------------")
print(" 学生管理系统 V1.0")
print(" 1:添加学生")
print(" 2:删除学生")
print(" 3:修改学生")
print(" 4:查询学生")
print(" 5:显示所有学生")
print(" 6:退出系统")
print("---------------------------")
def add_student():
global class_info
name = input("请输入添加学生的姓名: >>>")
age = int(input("请输入添加学生的年龄: >>>"))
score = int(input("请输入添加学生的成绩: >>>"))
for student in class_info:
if student["name"] == name:
print("您输入的学生已经存在!")
return -1
if 0 >= age:
print("您输入的年龄有误!")
return -2
if 0 > score or score > 101:
print("您输入的成绩有误!")
return -3
student = {
"name": name,
"age": age,
"score": score
}
class_info.append(student)
print("恭喜您,添加成功")
return 0
def del_student():
global class_info
name = input("请输入需要删除的学生姓名: >>>")
for student in class_info:
if student["name"] == name:
class_info.remove(student)
print("删除成功!")
return 0
print("您输入的学生不存在")
return -1
def modify_student():
global class_info
name = input("请输入需要修改的学生姓名: >>>")
for student in class_info:
if student["name"] == name:
age = int(input("请输入修改后的年龄: >>>"))
score = int(input("请输入修改后的成绩: >>>"))
if 0 >= age:
print("您输入的年龄有误!")
return -2
if 0 > score or score > 101:
print("您输入的成绩有误!")
return -3
student["age"] = age
student["score"] = score
print("修改成功!")
return 0
print("您输入的学生不存在")
return -1
def query_student():
global class_info
name = input("请输入需要查询的学生姓名: >>>")
for student in class_info:
if student["name"] == name:
print("姓名:", student["name"], "年龄:", student["age"], "成绩:", student["score"])
return 0
print("您输入的学生不存在")
return -1
def show_all_students():
global class_info
for student in class_info:
print("姓名:", student["name"], "年龄:", student["age"], "成绩:", student["score"])
def main():
while True:
print_menu()
choose = int(input("请输入您的选择: >>>"))
if choose == 1:
add_student()
elif choose == 2:
del_student()
elif choose == 3:
modify_student()
elif choose == 4:
query_student()
elif choose == 5:
show_all_students()
elif choose == 6:
print("谢谢使用,再见!")
break
main()
```
你现在可以在命令行中运行这个程序,体验完整的学生管理系统了。希望能帮到你!