python学生信息管理系统简易版
时间: 2023-12-25 15:29:42 浏览: 94
以下是一个简易版的Python学生信息管理系统的示例:
```python
class Student:
def __init__(self, name, age, grade):
self.name = name
self.age = age
self.grade = grade
class StudentManagementSystem:
def __init__(self):
self.students = []
def add_student(self, name, age, grade):
student = Student(name, age, grade)
self.students.append(student)
def remove_student(self, name):
for student in self.students:
if student.name == name:
self.students.remove(student)
break
def get_student_info(self, name):
for student in self.students:
if student.name == name:
return f"Name: {student.name}, Age: {student.age}, Grade: {student.grade}"
return "Student not found"
def get_all_students(self):
student_info = ""
for student in self.students:
student_info += f"Name: {student.name}, Age: {student.age}, Grade: {student.grade}\n"
return student_info
# 创建学生信息管理系统对象
sms = StudentManagementSystem()
# 添加学生信息
sms.add_student("Alice", 18, "A")
sms.add_student("Bob", 17, "B")
sms.add_student("Charlie", 16, "C")
# 获取指定学生信息
print(sms.get_student_info("Alice")) # 输出:Name: Alice, Age: 18, Grade: A
# 移除学生信息
sms.remove_student("Bob")
# 获取所有学生信息
print(sms.get_all_students())
# 输出:
# Name: Alice, Age: 18, Grade: A
# Name: Charlie, Age: 16, Grade: C
```
阅读全文