Python 学生管理系统student = {"name" : name, "age" : age, "score" : score};def print_menu(): print("---------------------------") print(" 学生管理系统 V1.0") print(" 1:添加学生") print(" 2:删除学生") print(" 3:修改学生") print(" 4:查询学生") print(" 5:显示所有学生") print(" 6:退出系统") print("---------------------------")完成以上功能,用面向对象代码实现
时间: 2023-07-05 14:26:54 浏览: 57
好的,我来为您实现一个面向对象的学生管理系统。
```python
class Student:
def __init__(self, name, age, score):
self.name = name
self.age = age
self.score = score
class StudentManager:
def __init__(self):
self.students = []
def add_student(self):
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
score = input("请输入学生成绩:")
student = Student(name, age, score)
self.students.append(student)
print("添加学生成功!")
def delete_student(self):
name = input("请输入要删除的学生姓名:")
for student in self.students:
if student.name == name:
self.students.remove(student)
print("删除学生成功!")
return
print("没有找到该学生!")
def modify_student(self):
name = input("请输入要修改的学生姓名:")
for student in self.students:
if student.name == name:
age = input("请输入学生年龄:")
score = input("请输入学生成绩:")
student.age = age
student.score = score
print("修改学生成功!")
return
print("没有找到该学生!")
def query_student(self):
name = input("请输入要查询的学生姓名:")
for student in self.students:
if student.name == name:
print("姓名:{},年龄:{},成绩:{}".format(student.name, student.age, student.score))
return
print("没有找到该学生!")
def show_students(self):
for student in self.students:
print("姓名:{},年龄:{},成绩:{}".format(student.name, student.age, student.score))
def exit_system(self):
print("谢谢使用!")
exit()
def run(self):
while True:
print("---------------------------")
print(" 学生管理系统 V1.0")
print(" 1:添加学生")
print(" 2:删除学生")
print(" 3:修改学生")
print(" 4:查询学生")
print(" 5:显示所有学生")
print(" 6:退出系统")
print("---------------------------")
choice = input("请输入操作编号:")
if choice == "1":
self.add_student()
elif choice == "2":
self.delete_student()
elif choice == "3":
self.modify_student()
elif choice == "4":
self.query_student()
elif choice == "5":
self.show_students()
elif choice == "6":
self.exit_system()
else:
print("输入有误,请重新输入!")
```
以上就是一个简单的面向对象的学生管理系统,您可以根据需要进行修改和扩展。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)