基于python的体育场管理系统
时间: 2023-09-02 18:08:59 浏览: 166
课程设计python实现田径运动会管理系统源码+数据库.zip
5星 · 资源好评率100%
体育场管理系统一般包括场馆预订、场馆管理、票务管理、会员管理等模块。下面是一个基于Python的简单体育场管理系统的示例代码:
```python
import datetime
class Venue:
def __init__(self, name, capacity):
self.name = name
self.capacity = capacity
self.bookings = []
def check_availability(self, start_time, end_time):
for booking in self.bookings:
if (start_time < booking["end_time"]) and (end_time > booking["start_time"]):
return False
return True
def book(self, start_time, end_time, customer):
if self.check_availability(start_time, end_time):
if len(self.bookings) < self.capacity:
self.bookings.append({
"start_time": start_time,
"end_time": end_time,
"customer": customer
})
print(f"Booking successful for {customer} at {self.name} from {start_time} to {end_time}.")
else:
print(f"{self.name} is already fully booked for this time slot.")
else:
print(f"{self.name} is not available for this time slot.")
class BookingSystem:
def __init__(self):
self.venues = []
def add_venue(self, venue):
self.venues.append(venue)
def list_venues(self):
print("Available Venues:")
for i, venue in enumerate(self.venues):
print(f"{i+1}. {venue.name}")
def book_venue(self, venue_name, start_time, end_time, customer):
for venue in self.venues:
if venue.name == venue_name:
venue.book(start_time, end_time, customer)
return
print(f"{venue_name} not found.")
def list_bookings(self):
print("Current Bookings:")
for venue in self.venues:
for booking in venue.bookings:
print(f"{venue.name} - {booking['customer']} - {booking['start_time']} to {booking['end_time']}")
if __name__ == "__main__":
bs = BookingSystem()
# Add venues to the system
bs.add_venue(Venue("Stadium A", 3))
bs.add_venue(Venue("Stadium B", 2))
# List available venues
bs.list_venues()
# Book a venue
bs.book_venue("Stadium A", datetime.datetime(2022, 1, 1, 12), datetime.datetime(2022, 1, 1, 14), "John")
# List current bookings
bs.list_bookings()
```
这个示例代码中定义了两个类,`Venue`和`BookingSystem`。`Venue`表示一个场馆,包括名称、容量和当前预订信息;`BookingSystem`表示整个预订系统,包括场馆列表、场馆添加、场馆预订、预订列表等功能。在`Venue`中,`check_availability`方法用于检查某个时间段是否可用,`book`方法用于预订某个时间段。在`BookingSystem`中,`add_venue`方法用于添加场馆,`list_venues`方法用于列出可用场馆,`book_venue`方法用于预订场馆,`list_bookings`方法用于列出当前预订。通过在`if __name__ == "__main__":`中编写示例代码,可以测试预订系统的功能。
阅读全文