""" 编写一个酒店管理系统 有一个酒店 十层楼 每层楼 十个房间 每个房间的表示形式 101空 808满 顾客入住酒店 只需要在控制台上输入指令即可办理服务 select---> 查看酒店的所有房间状态 in------->办理入住 询问需要入住的 房间号,若满足条件则办理入住 若入住成功 则:101空----->101满 out------->办理退房 询问要退出的房间号 ,若满足条件则 办理退房 若入住成功 则:101满----->101空 change------->办理退房 询问之前入住的房间号 和要更换的新房间号 满足条件则换房 """
时间: 2023-08-15 19:56:02 浏览: 199
好的,我会为您编写一个简单的酒店管理系统。以下是代码示例:
```python
class HotelManagementSystem:
def __init__(self):
self.hotel = [[101, 101, 101, 101, 101, 101, 101, 101, 101, 101] for _ in range(10)] # 初始化酒店房间状态
def show_room_status(self):
for floor, rooms in enumerate(self.hotel):
print(f"第{floor + 1}层房间状态:")
for room in rooms:
status = "满" if room == 808 else "空"
print(f"房间{room}:{status}")
print()
def check_in(self, room_number):
floor = (room_number - 101) // 10
room = (room_number - 101) % 10
if self.hotel[floor][room] == 101:
self.hotel[floor][room] = 808
print(f"房间{room_number}入住成功!")
else:
print(f"房间{room_number}已经被占用,请选择其他房间。")
def check_out(self, room_number):
floor = (room_number - 101) // 10
room = (room_number - 101) % 10
if self.hotel[floor][room] == 808:
self.hotel[floor][room] = 101
print(f"房间{room_number}退房成功!")
else:
print(f"房间{room_number}当前为空房,无需退房。")
def change_room(self, old_room_number, new_room_number):
floor_old = (old_room_number - 101) // 10
room_old = (old_room_number - 101) % 10
floor_new = (new_room_number - 101) // 10
room_new = (new_room_number - 101) % 10
if self.hotel[floor_old][room_old] == 808 and self.hotel[floor_new][room_new] == 101:
self.hotel[floor_old][room_old] = 101
self.hotel[floor_new][room_new] = 808
print(f"房间{old_room_number}更换到房间{new_room_number}成功!")
else:
print(f"更换房间失败,请检查房间状态。")
# 测试代码
hotel_system = HotelManagementSystem()
while True:
command = input("请输入指令(select/in/out/change/exit):")
if command == "select":
hotel_system.show_room_status()
elif command == "in":
room_number = int(input("请输入要入住的房间号:"))
hotel_system.check_in(room_number)
elif command == "out":
room_number = int(input("请输入要退房的房间号:"))
hotel_system.check_out(room_number)
elif command == "change":
old_room_number = int(input("请输入之前入住的房间号:"))
new_room_number = int(input("请输入要更换的新房间号:"))
hotel_system.change_room(old_room_number, new_room_number)
elif command == "exit":
break
else:
print("无效的指令,请重新输入。")
```
这是一个简单的酒店管理系统,您可以通过输入指令来办理入住、退房和换房等服务。希望对您有帮助!
阅读全文