python酒店管理系统代码
时间: 2023-10-12 10:43:03 浏览: 198
酒店管理系统代码
4星 · 用户满意度95%
当然,我可以提供一个简单的示例代码来实现一个基本的酒店管理系统。以下是一个使用Python的酒店管理系统的示例代码:
```python
class Hotel:
def __init__(self, name, rooms):
self.name = name
self.rooms = rooms
def check_availability(self):
available_rooms = [room for room in self.rooms if room.is_available()]
return available_rooms
def book_room(self, room_number):
for room in self.rooms:
if room.number == room_number:
if room.is_available():
room.book()
return f"Room {room_number} has been booked."
else:
return f"Room {room_number} is not available."
return f"Room {room_number} does not exist."
def check_out(self, room_number):
for room in self.rooms:
if room.number == room_number:
if not room.is_available():
room.check_out()
return f"Room {room_number} has been checked out."
else:
return f"Room {room_number} is already available."
return f"Room {room_number} does not exist."
class Room:
def __init__(self, number):
self.number = number
self.available = True
def is_available(self):
return self.available
def book(self):
self.available = False
def check_out(self):
self.available = True
# 创建酒店对象
hotel = Hotel("ABC Hotel", [Room(101), Room(102), Room(103)])
# 检查可用房间
available_rooms = hotel.check_availability()
print("Available Rooms:", [room.number for room in available_rooms])
# 预订房间
print(hotel.book_room(101))
# 再次检查可用房间
available_rooms = hotel.check_availability()
print("Available Rooms:", [room.number for room in available_rooms])
# 退房
print(hotel.check_out(101))
# 最后检查可用房间
available_rooms = hotel.check_availability()
print("Available Rooms:", [room.number for room in available_rooms])
```
这个示例代码使用了两个类:`Hotel`和`Room`。`Hotel`类代表一个酒店,具有酒店的名称和房间列表。`Room`类代表一个房间,具有房间号和是否可用的状态。
在示例中,我们首先创建一个酒店对象,然后检查可用房间,预订一个房间,再次检查可用房间,最后退房并再次检查可用房间。
请注意,这只是一个简单的示例代码,实际的酒店管理系统可能需要更多功能和更复杂的实现。
阅读全文