Introduction:
In this tutorial, we will create a Hotel Management System project using Python. This project will allow us to manage the various aspects of a hotel such as booking rooms, managing customers, and processing payments.
Prerequisites:
To follow along with this tutorial, you will need to have Python installed on your computer. You can download Python from the official website (https://www.python.org/). You will also need to have a basic understanding of Python programming language and object-oriented programming concepts.
Step 1: Create a Python Class for Rooms
To start our project, let’s create a Python class for representing rooms in a hotel. Each room will have attributes such as room number, type (single, double, etc.), price, and availability status. We will also create methods for booking and releasing rooms.
class Room:
def __init__(self, number, type, price, is_booked=False):
self.number = number
self.type = type
self.price = price
self.is_booked = is_booked
def book_room(self):
if not self.is_booked:
self.is_booked = True
print(f"Room {self.number} has been booked.")
else:
print(f"Room {self.number} is already booked.")
def release_room(self):
if self.is_booked:
self.is_booked = False
print(f"Room {self.number} has been released.")
else:
print(f"Room {self.number} is already available.")
Step 2: Create a Python Class for Customers
Next, let’s create a Python class for representing customers. Each customer will have attributes such as name, email, and booking history. We will also create methods for booking a room and processing payments.
class Customer:
def __init__(self, name, email):
self.name = name
self.email = email
self.booking_history = []
def book_room(self, room):
if not room.is_booked:
room.book_room()
self.booking_history.append(room.number)
print(f"{self.name} has booked Room {room.number}.")
else:
print(f"{self.name} could not book Room {room.number} as it is already booked.")
def process_payment(self, amount):
print(f"{self.name} has made a payment of ${amount}.")
Step 3: Create a Hotel Management System Class
Now, let’s create a Hotel Management System class that will manage the rooms and customers in our hotel. We will initialize the hotel with a list of available rooms and customers.
class HotelManagementSystem:
def __init__(self):
self.rooms = [Room(101, 'single', 100), Room(102, 'double', 150), Room(103, 'single', 100)]
self.customers = []
def add_customer(self, customer):
self.customers.append(customer)
def find_room_by_number(self, room_number):
for room in self.rooms:
if room.number == room_number:
return room
return None
Step 4: Testing the Hotel Management System
Let’s test our Hotel Management System by creating some customers and booking rooms for them.
# Create Hotel Management System
hms = HotelManagementSystem()
# Create Customers
john = Customer("John Doe", "john.doe@email.com")
jane = Customer("Jane Smith", "jane.smith@email.com")
# Add Customers to Hotel Management System
hms.add_customer(john)
hms.add_customer(jane)
# Book Rooms for Customers
john_room = hms.find_room_by_number(101)
jane_room = hms.find_room_by_number(102)
john.book_room(john_room)
jane.book_room(jane_room)
# Process Payments
john.process_payment(john_room.price)
jane.process_payment(jane_room.price)
# Release Rooms
john_room.release_room()
jane_room.release_room()
Conclusion:
In this tutorial, we have created a simple Hotel Management System project using Python. This project demonstrates how we can use classes and objects to model a real-world system and manage its components. You can further enhance this project by adding more functionality such as checking room availability, processing refunds, and generating reports. Happy coding!
wow yaar