写一个基于python的校园宿舍管理系统代码,不需要添加其他东西
时间: 2024-05-01 12:18:55 浏览: 113
wxcrm:校园管理系统
好的,以下是一个简单的基于Python的校园宿舍管理系统代码:
```python
# 宿舍管理系统
# 宿舍信息
dormitories = {
"1号楼": {"101": "张三", "102": "李四", "103": "王五"},
"2号楼": {"201": "赵六", "202": "钱七", "203": "孙八"},
"3号楼": {"301": None, "302": None, "303": None}
}
# 显示所有宿舍信息
def show_dormitories():
for building, rooms in dormitories.items():
print(building)
for room, student in rooms.items():
print(" ", room, student)
# 添加学生
def add_student():
building = input("请输入楼号:")
room = input("请输入房间号:")
if building not in dormitories:
print("该楼号不存在")
return
if room not in dormitories[building]:
print("该房间号不存在")
return
if dormitories[building][room] is not None:
print("该房间已有人")
return
student_name = input("请输入学生姓名:")
dormitories[building][room] = student_name
print("添加成功")
# 删除学生
def remove_student():
building = input("请输入楼号:")
room = input("请输入房间号:")
if building not in dormitories:
print("该楼号不存在")
return
if room not in dormitories[building]:
print("该房间号不存在")
return
if dormitories[building][room] is None:
print("该房间没有人")
return
dormitories[building][room] = None
print("删除成功")
# 主菜单
def main_menu():
while True:
print("1. 显示所有宿舍信息")
print("2. 添加学生")
print("3. 删除学生")
print("4. 退出程序")
choice = input("请输入你的选择:")
if choice == "1":
show_dormitories()
elif choice == "2":
add_student()
elif choice == "3":
remove_student()
elif choice == "4":
break
else:
print("无效的选择")
# 运行程序
main_menu()
```
以上代码实现了一个简单的校园宿舍管理系统,可以显示所有宿舍信息、添加学生、删除学生。你可以根据需要进行修改和扩展。
阅读全文