You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB

6 months ago
import datetime
class Room:
def __init__(self, room_number, room_type, rate, availability=True):
self.room_number = room_number
self.room_type = room_type
self.rate = rate
self.availability = availability
class Reservation:
def __init__(self, room, start_date, end_date):
self.room = room
self.start_date = start_date
self.end_date = end_date
self.total_cost = self.calculate_tatal_cost()
def calculate_total_cost(self):
days = (self.end_date - self.start_date).days
return days * self.room.rate
class Hotel:
def __init__(self, name):
self.name = name
self.rooms = []
self.reservations = []
6 months ago
def add_room(self, room):
self.rooms.append(room)
def check_availability(self, start_date, end_date):
available_rooms = [r for r in self.rooms if r.availability and
not any((start_date <= res.start_date <= end_date or start_date <= res.end_date <= end_date)
for res in self.reservations if res.room == r)]
return available_rooms