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
| Component | Description |
|---|---|
| Programming Language | Python |
| Database | MySQL |
| Python Module | mysql-connector-python |
| Tabular Output | tabulate module |
| Platform | Windows |
| IDE | IDLE |
πΉ 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
| Attribute | Description |
|---|---|
| customer_id (Primary Key) | Unique customer ID |
| customer_name | Name of customer |
| checkin_date | Date of check-in |
| contact_no | Contact number |
| address | Customer address |
| room_type | AC / Non-AC |
| room_no | Room number |
π© ENTITY 2: RESTAURANT
| Attribute | Description |
|---|---|
| food_id (Primary Key) | Food order ID |
| customer_id (Foreign Key) | References customer |
| food_name | Name of food |
| qty | Quantity |
| price | Price per item |
π¨ ENTITY 3: CHECK_OUT
| Attribute | Description |
|---|---|
| customer_id (FK) | References customer |
| customer_name | Name of customer |
| checkout_date | Date of checkout |
| no_of_days_stay | Number of days |
| restaurant_bill | Total food bill |
| room_charges | Room charges |
| grand_total | Final bill amount |
πΉ 6. Functional Modules
The project is divided into the following functional modules:
- Add Customer β Registers a new customer
- Restaurant Order β Takes food orders
- Search Customer β Searches records from selected table
- Modify Customer β Updates customer details
- Delete Customer β Deletes customer if no dependency exists
- Show Records β Displays table records in tabular form
- Check Out β Calculates bill and generates invoice
- 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.