Python project on Hotel Management System

Python project on Hotel Management System



βœ… PYTHON FILE : hotel_management.py

import mysql.connector as sqlcon
from datetime import date
from tabulate import tabulate


# ---------------------------------
# Step 1: Connect to MySQL Server
# ---------------------------------
con = sqlcon.connect(
    host="localhost",
    user="root",
    #password="root"   # change if needed
)
cur = con.cursor()
cur.execute("CREATE DATABASE IF NOT EXISTS Hotel")
cur.execute("USE Hotel")


def Database_setup():            # used only first time
    # ---------------------------------
    # Step 2: Create Database if not exists
    # ---------------------------------
    cur.execute("CREATE DATABASE IF NOT EXISTS Hotel")
    cur.execute("USE Hotel")

    # ---------------------------------
    # Step 3: Create Tables if not exists
    # ---------------------------------

    # CUSTOMER TABLE
    cur.execute("""
    CREATE TABLE IF NOT EXISTS customer (
        customer_id INT AUTO_INCREMENT PRIMARY KEY,
        customer_name VARCHAR(50),
        checkin_date DATE,
        contact_no VARCHAR(15),
        address VARCHAR(100),
        room_type VARCHAR(10),
        room_no INT
    )
    """)

    # RESTAURANT TABLE
    cur.execute("""
    CREATE TABLE IF NOT EXISTS restaurant (
        food_id INT AUTO_INCREMENT PRIMARY KEY,
        customer_id INT,
        food_name VARCHAR(50),
        qty INT,
        price INT,
        FOREIGN KEY (customer_id) REFERENCES customer(customer_id)
    )
    """)

    # CHECK OUT TABLE
    cur.execute("""
    CREATE TABLE IF NOT EXISTS check_out (
        customer_id INT,
        customer_name VARCHAR(50),
        checkout_date DATE,
        no_of_days_stay INT,
        restaurant_bill INT,
        room_charges INT,
        grand_total INT
    )
    """)

    print("βœ… Database and tables checked/created successfully")

    # ------------------------------------------------
    # Step 4: Insert records only if customer table empty
    # ------------------------------------------------
    cur.execute("SELECT COUNT(*) FROM customer")
    count = cur.fetchone()[0]

    if count == 0:
        insert_query = """
        INSERT INTO customer
        (customer_name, checkin_date, contact_no, address, room_type, room_no)
        VALUES (%s,%s,%s,%s,%s,%s)
        """

        records = [
            ('Amit Kumar', '2025-07-01', '9876543210', 'Delhi', 'AC', 101),
            ('Riya Sharma', '2025-07-02', '9123456780', 'Mumbai', 'Non-AC', 102),
            ('Rahul Verma', '2025-07-03', '9988776655', 'Jaipur', 'AC', 103),
            ('Neha Singh', '2025-07-04', '8899001122', 'Lucknow', 'Non-AC', 104),
            ('Pooja Mehta', '2025-07-05', '7766554433', 'Indore', 'AC', 105)
        ]

        cur.executemany(insert_query, records)
        con.commit()
        print("βœ… Dummy customer records inserted successfully")
    else:
        print("β„Ή Customer table already has data. No insertion done.")


# ---------------- FUNCTIONS ---------------- #

def add_customer():
    name = input("Enter customer name: ")
    checkin = input("Enter check-in date (YYYY-MM-DD): ")
    contact = input("Enter contact number: ")
    address = input("Enter address: ")
    room_type = input("Enter room type (AC / Non-AC): ")
    room_no = int(input("Enter room number: "))

    sql = """INSERT INTO customer
             (customer_name, checkin_date, contact_no, address, room_type, room_no)
             VALUES (%s,%s,%s,%s,%s,%s)"""
    cur.execute(sql, (name, checkin, contact, address, room_type, room_no))
    con.commit()
    print("Customer added successfully")


def restaurant_order():
    
    #food_id = int(input("Enter food id: "))
    cid = int(input("Enter customer id: "))
    #verify customer id    
    cur.execute("SELECT customer_id FROM customer where customer_id={}".format(cid))
    cust_found = cur.fetchone()
    if cust_found:
        pass
    else:
        print("customer id not exist.")
        return
    
    food_menu  = {
    1: "Burger = Rs.250",
    2: "Pizza = Rs.350",
    3: "Pasta = Rs.300",
    4: "Sandwich = Rs.200",
    5: "French Fries = Rs.180",
    6: "Noodles = Rs.220",
    7: "Fried Rice = Rs.240",
    8: "Manchurian = Rs.260",
    9: "Spring Roll = Rs.190",
    10: "Momos = Rs.210",
    11: "Paneer Tikka = Rs.320",
    12: "Dal Makhani = Rs.280",
    13: "Butter Naan = Rs.60",
    14: "Veg Biryani = Rs.300",
    15: "Jeera Rice = Rs.200",
    16: "Idli = Rs.120",
    17: "Dosa = Rs.180",
    18: "Vada = Rs.100",
    19: "Samosa = Rs.50",
    20: "Chole Bhature = Rs.220"}
    for item_no, item in food_menu.items():
        print(f"{item_no}. {item}")

    f = int(input("select food name from the list: "))
    food=food_menu.get(f)
    print("You selected =>:",food)
    qty = int(input("Enter quantity: "))
    
    pr=""
    for d in food:
        if d.isdigit():
            pr+=d
    print("Price=",int(pr))            
    price = int(pr)
    confirm=input("Want to place order?y/n")

    if confirm.upper() =="y".upper():        
        cur.execute(
            "INSERT INTO restaurant(customer_id,food_name,qty,price) VALUES (%s,%s,%s,%s)",
            (cid, food, qty, price)
        )
        con.commit()
        print("Item has been orderd.")
    


def modify_customer():
    cid = int(input("Enter customer id: "))
    name = input("Enter new name: ")
    room = input("Enter new room type (AC / Non-AC): ")

    cur.execute(
        "UPDATE customer SET customer_name=%s, room_type=%s WHERE customer_id=%s",
        (name, room, cid)
    )
    con.commit()
    print("Customer record updated")


def search_customer():
    cid = int(input("Enter customer id: "))
    print("1. Customer\n2. Restaurant\n3. Check Out")
    ch = int(input("Choose table: "))

    tables = {1: "customer", 2: "restaurant", 3: "check_out"}
    table = tables.get(ch)

    cur.execute(f"SELECT * FROM {table} WHERE customer_id=%s", (cid,))
    rows = cur.fetchall()

    if rows:
        print(tabulate(rows, tablefmt="grid"))
    else:
        print("Record not found")


def delete_customer():
    cid = int(input("Enter customer id: "))

    cur.execute("SELECT * FROM restaurant WHERE customer_id=%s", (cid,))
    if cur.fetchone():
        print("Cannot delete. Customer need to check out...")
        return

    cur.execute("DELETE FROM customer WHERE customer_id=%s", (cid,))
    con.commit()
    print("Customer deleted")


def check_out():
    cid = int(input("Enter customer id: "))
    checkout_date = date.today()

    cur.execute(
        "SELECT customer_name, checkin_date, room_type FROM customer WHERE customer_id=%s",
        (cid,)
    )
    rec = cur.fetchone()

    if not rec:
        print("Customer not found")
        return

    name, checkin_date, room_type = rec
    days = (checkout_date - checkin_date).days
    if days == 0:
        days = 1

    cur.execute(
        "SELECT food_name, qty, price, qty*price FROM restaurant WHERE customer_id=%s",
        (cid,)
    )
    food_data = cur.fetchall()

    restaurant_bill = 0
    if food_data:
        for row in food_data:
            restaurant_bill += row[3]

    if room_type == "AC":
        room_charges = days * 4000
    else:
        room_charges = days * 2000

    grand_total = restaurant_bill + room_charges

    # Insert into checkout table
    cur.execute(
        "INSERT INTO check_out VALUES (%s,%s,%s,%s,%s,%s,%s)",
        (cid, name, checkout_date, days, restaurant_bill, room_charges, grand_total)
    )

    # ---------------- INVOICE ---------------- #
    print("\n=========== HOTEL INVOICE ===========")
    print(f"Customer ID   : {cid}")
    print(f"Customer Name : {name}")
    print(f"Check-in Date : {checkin_date}")
    print(f"Check-out Date: {checkout_date}")
    print(f"Days Stayed   : {days}")
    print(f"Room Type     : {room_type}")

    if food_data:
        print("\n--- Restaurant Bill ---")
        print(tabulate(
            food_data,
            headers=["Food Name", "Qty", "Price", "Total"],
            tablefmt="grid"
        ))
    else:
        print("\nNo restaurant orders")

    print("\n--- Charges Summary ---")
    summary = [
        ["Restaurant Bill", restaurant_bill],
        ["Room Charges", room_charges],
        ["Grand Total", grand_total]
    ]
    print(tabulate(summary, tablefmt="grid"))

    print("====================================")

    # Remove records
    cur.execute("DELETE FROM restaurant WHERE customer_id=%s", (cid,))
    cur.execute("DELETE FROM customer WHERE customer_id=%s", (cid,))
    con.commit()

    print("Check-out completed successfully")


def show_customer():
    print("1. Customer\n2. Restaurant\n3. Check Out")
    ch = int(input("Choose table: "))

    tables = {1: "customer", 2: "restaurant", 3: "check_out"}
    if ch==1:
        table_name="Customer"
        head=["Cid","Name","Cin_date","Ph","Address","Rm_type","Rm_no"]
        sql="SELECT * FROM customer"
    elif ch==2:
        table_name="Restaurant"         
        head=["FoodId","Cid","CName","Food","Qty","Price"]
        sql="SELECT food_id,r.customer_id,customer_name,food_name,qty,price FROM restaurant r, customer c where r.customer_id=c.customer_id"
    elif ch==3:
        table_name="Check_out"
        head=["Cid","Name","Chk_out","Days","Res_bill","Rm_charg","Total"]
        sql="SELECT * FROM check_out"

    #table = tables.get(ch)
    #cur.execute(f"SELECT * FROM {table}")
    cur.execute(sql)
    rows = cur.fetchall()

    if rows:
        print("=================================="+table_name+"=====================")
        print(tabulate(rows,headers=head, tablefmt="grid"))
    else:
        print("No records found")


# ---------------- MAIN MENU ---------------- #

while True:
    print("\n--- HOTEL MANAGEMENT SYSTEM ---")
    print("1. Add customer")
    print("2. Restaurant order")
    print("3. Search customer")
    print("4. Modify customer")
    print("5. Delete customer")
    print("6. Show records")
    print("7. Check out")
    print("8. Setup Database")
    print("9. Exit")

    choice = input("Enter choice: ")

    if choice == '1':
        add_customer()
    elif choice == '2':
        restaurant_order()
    elif choice == '3':
        search_customer()
    elif choice == '4':
        modify_customer()
    elif choice == '5':
        delete_customer()
    elif choice == '6':
        show_customer()
    elif choice == '7':
        check_out()
    elif choice == '8':
        Database_setup()
    elif choice == '9':
        print("Thank you")
        break
    else:
        print("Invalid choice")

πŸ“ PROJECT STRUCTURE

πŸ“Hotel_Management_System/
β”‚
β”œβ”€β”€ hotel_DB.sql β†’ MySQL database file
└── hotel_management.py β†’ Main Python program

HOW TO RUN (STEP-BY-STEP)

βœ… Step 1: Install MySQL Connector & tabulate

Open command prompt and run the following commands:

pip install mysql-connector-python
pip install tabulate

βœ… Step 2: Run Python Program

python hotel_management.py

πŸ“˜ PROJECT REPORT

HOTEL MANAGEMENT SYSTEM

πŸ“„ ACKNOWLEDGEMENT

I would like to express my sincere gratitude to my Computer Science teacher for their valuable guidance, encouragement, and constant support throughout the development of this project.
I am also thankful to my school for providing the necessary resources and facilities to complete this project successfully. I would like to thank my parents and friends for their cooperation and motivation during the project work. This project has helped me to enhance my knowledge of Python programming, MySQL database, and their real-life applications.

πŸ“œ CERTIFICATE

This is to certify that __________________________ (Student Name),
student of Class XII, has successfully completed the project titled
β€œHotel Management System” in Computer Science (083) during the academic year 2025–2026.
This project is an original work carried out by the student under my supervision and is in accordance with the CBSE syllabus.
I wish the student every success in future endeavors.
Teacher’s Name: ______________________
Subject: Computer Science
School Name: ________________________
Signature: __________________________
Date: ______________________________

πŸ”Ή 1. Introduction

The Hotel Management System is a Python-based application developed to manage basic hotel operations such as customer registration, room allocation, restaurant billing, and checkout process.
This project is designed strictly according to the CBSE Class XII Computer Science syllabus, using simple Python concepts and MySQL database connectivity.

The system helps hotel staff to maintain customer records in a systematic manner, reduce paperwork, and generate accurate bills. It is a menu-driven program that provides an easy-to-use interface for managing hotel activities.


πŸ”Ή 2. Objectives of the Project

The main objectives of this project are:

  • To computerize hotel record management
  • To store and retrieve customer details efficiently
  • To manage restaurant orders and billing
  • To calculate room charges and total bill during checkout
  • To generate invoice in tabular format
  • To understand practical use of Python with MySQL database

πŸ”Ή 3. Scope of the Project

This project is suitable for small to medium hotels.
It covers the following operations:

  • Customer registration
  • Restaurant food order management
  • Customer search and modification
  • Secure deletion of records
  • Checkout and invoice generation

The project can be further enhanced in the future by adding features like payment modes, staff management, and graphical user interface.


πŸ”Ή 4. Tools & Technologies Used

ComponentDescription
Programming LanguagePython
DatabaseMySQL
Python Modulemysql-connector-python
Tabular Outputtabulate module
PlatformWindows
IDEIDLE

πŸ”Ή 5. Database Design

The project uses a MySQL database named Hotel consisting of three tables:

(a) Customer Table

Stores customer and room details.

(b) Restaurant Table

Stores food order details of customers.

(c) Check_out Table

Stores billing and checkout details including:

  • Number of days stayed
  • Restaurant bill
  • Room charges
  • Grand total

πŸ”Ή 1. Entities and Attributes

🟦 ENTITY 1: CUSTOMER

AttributeDescription
customer_id (Primary Key)Unique customer ID
customer_nameName of customer
checkin_dateDate of check-in
contact_noContact number
addressCustomer address
room_typeAC / Non-AC
room_noRoom number

🟩 ENTITY 2: RESTAURANT

AttributeDescription
food_id (Primary Key)Food order ID
customer_id (Foreign Key)References customer
food_nameName of food
qtyQuantity
pricePrice per item

🟨 ENTITY 3: CHECK_OUT

AttributeDescription
customer_id (FK)References customer
customer_nameName of customer
checkout_dateDate of checkout
no_of_days_stayNumber of days
restaurant_billTotal food bill
room_chargesRoom charges
grand_totalFinal bill amount

πŸ”Ή 6. Functional Modules

The project is divided into the following functional modules:

  1. Add Customer – Registers a new customer
  2. Restaurant Order – Takes food orders
  3. Search Customer – Searches records from selected table
  4. Modify Customer – Updates customer details
  5. Delete Customer – Deletes customer if no dependency exists
  6. Show Records – Displays table records in tabular form
  7. Check Out – Calculates bill and generates invoice
  8. Database_setup – Used to setup database before running the project

πŸ”Ή 7. Working of the System

The system starts with a menu-driven interface.
The user selects an option by entering a number.
Based on the choice, the corresponding function is executed.

During checkout:

  • Number of days is calculated using check-in and check-out dates
  • Room charges are calculated based on room type
  • Restaurant bill is calculated from food orders
  • A final invoice is displayed in tabular format

πŸ”Ή 8. Advantages of the System

  • Reduces manual work
  • Faster data retrieval
  • Accurate billing
  • Easy to understand and operate
  • Improves efficiency and record management

πŸ”Ή 9. Limitations

  • No graphical user interface
  • Designed for single-user access
  • Limited security features
  • Internet-based features not included

πŸ”Ή 10. Conclusion

The Hotel Management System successfully demonstrates the practical application of Python programming and MySQL database connectivity.
It fulfills all CBSE Class XII project requirements and provides hands-on experience in database handling, functions, and menu-driven programming.


Download source code

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top