用Python设计一个教室信息管理系统
时间: 2024-04-07 17:11:41 浏览: 113
好的,下面是一个简单的教室信息管理系统,可以记录教室的编号、容量、位置等信息,并且可以进行增加、删除、修改和查询操作。
```python
class Classroom:
def __init__(self, id, capacity, location):
self.id = id
self.capacity = capacity
self.location = location
class ClassroomManagementSystem:
def __init__(self):
self.classrooms = []
def add_classroom(self, classroom):
self.classrooms.append(classroom)
def remove_classroom(self, id):
for classroom in self.classrooms:
if classroom.id == id:
self.classrooms.remove(classroom)
return True
return False
def update_classroom(self, id, capacity, location):
for classroom in self.classrooms:
if classroom.id == id:
classroom.capacity = capacity
classroom.location = location
return True
return False
def search_classroom(self, id):
for classroom in self.classrooms:
if classroom.id == id:
return classroom
return None
```
使用示例:
```python
# 创建教室管理系统
cms = ClassroomManagementSystem()
# 添加教室
cms.add_classroom(Classroom(1, 100, 'A101'))
cms.add_classroom(Classroom(2, 50, 'B201'))
# 删除教室
cms.remove_classroom(2)
# 修改教室
cms.update_classroom(1, 80, 'A102')
# 查询教室
classroom = cms.search_classroom(1)
if classroom:
print(f'教室编号:{classroom.id},容量:{classroom.capacity},位置:{classroom.location}')
else:
print('未找到该教室')
```
阅读全文