Cs Project File Final
Cs Project File Final
SCHOOL
RANIPUR,
HARIDWAR
PROJECT FILE
COMPUTER SCIENCE
SESSION: 2024-25
1. Certificate 3
3. Introduction 5
6. List of functions 16
7. Source Code 19
8. Output Screen
CERTIFICATE
This is to certify that Hotel Management Informatics Practices
project is developed by and Nilayansh Upadhyay and Apoorva
Singht under my supervision in the computer lab of in the session
2019-2020. The work done by them is original.
HARDWARES
Desktop Computer / Laptop
Mobile Phone
SOFTWARES
Python (Latest Version)
MySQL
MySQL-Connector Python, Requests, Wikipedia-API,
Datetime, Pyfiglet Modules
MYSQL TABLE STRUCTURE
Guest Table:
SOURCE CODE
import mysql.connector
def display_menu():
print("\n--- Hotel Management System ---")
print("1. Show all guest records")
print("2. Add a new guest record")
print("3. Search for a guest record")
print("4. Delete a guest record")
print("5. Update a guest record")
print("6. Exit")
def show_all_records():
db = connect_db()
cursor = db.cursor()
query = "SELECT * FROM guest;"
cursor.execute(query)
results = cursor.fetchall()
print("\nGuest Records:")
for row in results:
print(" | ".join(map(str, row)))
db.close()
def add_record():
db = connect_db()
cursor = db.cursor()
cursor.execute(query, values)
db.commit()
print("Record added successfully!")
db.close()
def search_record():
db = connect_db()
cursor = db.cursor()
print("1. Search by ID\n2. Search by Name\n3. Search by Room Type")
choice = int(input("Enter your choice: "))
if choice == 1:
guest_id = int(input("Enter Guest ID: "))
query = "SELECT * FROM guest WHERE guestid = %s;"
cursor.execute(query, (guest_id,))
elif choice == 2:
name = input("Enter Guest Name: ")
query = "SELECT * FROM guest WHERE nameofguest LIKE %s;"
cursor.execute(query, ("%" + name + "%",))
elif choice == 3:
room_type = input("Enter Room Type: ")
query = "SELECT * FROM guest WHERE type_of_room = %s;"
cursor.execute(query, (room_type,))
else:
print("Invalid choice.")
db.close()
return
results = cursor.fetchall()
if results:
for row in results:
print(" | ".join(map(str, row)))
else:
print("No records found.")
db.close()
def delete_record():
db = connect_db()
cursor = db.cursor()
guest_id = int(input("Enter Guest ID to delete: "))
query = "DELETE FROM guest WHERE guestid = %s;"
cursor.execute(query, (guest_id,))
db.commit()
if cursor.rowcount > 0:
print("Record deleted successfully!")
else:
print("No record found with the given ID.")
db.close()
def update_record():
db = connect_db()
cursor = db.cursor()
guest_id = int(input("Enter Guest ID to update: "))
print("1. Update Name\n2. Update Room Type\n3. Update Number of Days")
choice = int(input("Enter your choice: "))
if choice == 1:
new_name = input("Enter new name: ")
query = "UPDATE guest SET nameofguest = %s WHERE guestid = %s;"
values = (new_name, guest_id)
elif choice == 2:
new_room_type = input("Enter new room type: ")
query = "UPDATE guest SET type_of_room = %s WHERE guestid = %s;"
values = (new_room_type, guest_id)
elif choice == 3:
new_days = int(input("Enter new number of days: "))
query = "UPDATE guest SET noofdays = %s WHERE guestid = %s;"
values = (new_days, guest_id)
else:
print("Invalid choice.")
db.close()
return
cursor.execute(query, values)
db.commit()
if cursor.rowcount > 0:
print("Record updated successfully!")
else:
print("No record found with the given ID.")
db.close()
# Main program
while True:
display_menu()
try:
choice = int(input("Enter your choice: "))
if choice == 1:
show_all_records()
elif choice == 2:
add_record()
elif choice == 3:
search_record()
elif choice == 4:
delete_record()
elif choice == 5:
update_record()
elif choice == 6:
print("Exiting the program. Goodbye!")
break
else:
print("Invalid choice. Please enter a number between 1 and 6.")
except ValueError:
print("Invalid input. Please enter a number.")
OUTPUTS:
1. ADDING A RECORD
2. DISPLAYING ALL THE RECORDS
3. DELETING A RECORD
4. UPDATING A RECORD
5. SEARCHING THE RECORD
REFERENCE
1. www.google.com/Python project
2. www.wikipedia.com/Python
3. Class Notes.