0% found this document useful (0 votes)
15 views13 pages

Hotel Management System Code Example

Uploaded by

Rudra Pratap
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

Hotel Management System Code Example

Uploaded by

Rudra Pratap
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CODING

CODING
import datetime

class Room:

def __init__(self, room_number, room_type, price):

self.room_number = room_number

self.room_type = room_type

[Link] = price

self.is_available = True

def __str__(self):

return f"Room {self.room_number}: {self.room_type} - ${[Link]} per night"

class Customer:

def __init__(self, name, contact):

[Link] = name

[Link] = contact

class Booking:

def __init__(self, customer, room, check_in, check_out):

[Link] = customer

[Link] = room

self.check_in = check_in

self.check_out = check_out

self.total_price = self.calculate_price()

def calculate_price(self):

duration = (self.check_out - self.check_in).days

return duration * [Link]


def __str__(self):

return (f"Booking for {[Link]}\n"

f"Room: {[Link].room_number} ({[Link].room_type})\n"

f"Check-in: {self.check_in}\n"

f"Check-out: {self.check_out}\n"

f"Total Price: ${self.total_price}")

class HotelManagementSystem:

def __init__(self):

[Link] = []

[Link] = []

[Link] = []

def add_room(self, room_number, room_type, price):

room = Room(room_number, room_type, price)

[Link](room)

print(f"Added {room}")

def view_available_rooms(self):

print("\nAvailable Rooms:")

available = False

for room in [Link]:

if room.is_available:

print(room)

available = True

if not available:

print("No rooms available.")

def add_customer(self, name, contact):

customer = Customer(name, contact)

[Link](customer)

return customer
def book_room(self, customer_name, contact, room_number, check_in_str, check_out_str):

check_in = [Link](check_in_str, "%Y-%m-%d").date()

check_out = [Link](check_out_str, "%Y-%m-%d").date()

room = next((room for room in [Link] if room.room_number == room_number and


room.is_available), None)

if not room:

print("Room not available!")

return

customer = self.add_customer(customer_name, contact)

booking = Booking(customer, room, check_in, check_out)

[Link](booking)

room.is_available = False

print("Booking successful:")

print(booking)

def checkout(self, room_number):

booking = next((b for b in [Link] if [Link].room_number == room_number), None)

if not booking:

print("Booking not found.")

return

[Link].is_available = True

[Link](booking)

print(f"Checked out {[Link]} from Room {[Link].room_number}")

def list_bookings(self):

print("\nAll Bookings:")

if not [Link]:

print("No bookings found.")

for booking in [Link]:


print(booking)

print("-" * 40)

def list_customers(self):

print("\nCustomer List:")

if not [Link]:

print("No customers registered.")

for customer in [Link]:

print(f"Name: {[Link]}, Contact: {[Link]}")

def main():

hms = HotelManagementSystem()

# Pre-adding some rooms

hms.add_room(101, "Single", 50)

hms.add_room(102, "Double", 80)

hms.add_room(103, "Suite", 120)

while True:

print("\n1. View Available Rooms")

print("2. Book a Room")

print("3. Checkout Room")

print("4. List All Bookings")

print("5. List Customers")

print("6. Exit")

choice = input("Enter your choice: ")

if choice == '1':

hms.view_available_rooms()

elif choice == '2':


name = input("Enter customer name: ")

contact = input("Enter contact info: ")

try:

room_number = int(input("Enter room number: "))

checkin = input("Enter check-in date (YYYY-MM-DD): ")

checkout = input("Enter check-out date (YYYY-MM-DD): ")

hms.book_room(name, contact, room_number, checkin, checkout)

except ValueError:

print("Invalid input. Please try again.")

elif choice == '3':

try:

room_number = int(input("Enter room number for checkout: "))

[Link](room_number)

except ValueError:

print("Invalid input. Please try again.")

elif choice == '4':

hms.list_bookings()

elif choice == '5':

hms.list_customers()

elif choice == '6':

print("Exiting...")

break

else:

print("Invalid choice. Please try again.")

if __name__ == "__main__":

main()
OUTPUT

You might also like