Professional Documents
Culture Documents
connector to Python
import mysql.connector
db = mysql.connector.connect(
host="localhost",
user="root",
password="mysql",
database="hotel_management_system"
)
cur = db.cursor()
#Creating Table
def addRoom():
print(" --- ENTER ROOM DETAILS --- ")
rno= int(input("Enter Room No. : "))
status= "Vacant"
cur.execute("INSERT INTO hotel(room_number,room_status)
VALUES({},'{}')".format(rno,status))
db.commit()
print(" --- ROOM ADDED SUCCESSFULLY --- ")
def showRooms():
cur.execute(" SELECT * FROM hotel ")
details= cur.fetchall()
if details:
for room in details:
print(room)
else:
print("SORRY WE HAVE NO ROOMS")
def showVacantRooms():
cur.execute(" SELECT * FROM hotel WHERE room_status='Vacant' ")
details= cur.fetchall()
if details:
for Vroom in details:
print(Vroom)
else:
print("SORRY WE HAVE NO VACANT ROOMS AT THE MOMENT")
def showOccupiedRooms():
cur.execute(" SELECT * FROM hotel WHERE room_status='Occupied' ")
details= cur.fetchall()
if details:
for Oroom in details:
print(Oroom)
else:
print("WE HAVE NO OCCUPIED ROOMS")
def roomType():
print("We have 3 types of Rooms in our hotel :")
print(" Simple Room (Cost = Rs.2000) ")
print(" Deluxe Room (Cost = Rs.4000) ")
print(" Premium Room (Cost = Rs.6000) ")
#Function to decide cost of room booked per day as per the type of room
t='Simple'
u='Deluxe'
v='Premium'
def cost(type):
global f
if type== t :
print("You chose a Simple Room. Your fee for the day is Rs.2000")
cur.execute(" UPDATE hotel SET room_type='Simple' WHERE room_number=%s",
(r,))
f=2000
return f
elif type== u:
print("You chose a Deluxe Room. Your fee for the day is Rs.4000")
cur.execute(" UPDATE hotel SET room_type='Deluxe' WHERE room_number=%s",
(r,))
f=4000
return f
elif type== v :
print("You chose a Premium Room. Your fee for the day is Rs.6000")
cur.execute(" UPDATE hotel SET room_type='Premium' WHERE room_number=%s",
(r,))
f=6000
return f
else:
print("Invalid choice")
#Function to book a room
def bookRoom():
global r
name= eval(input("Enter Your Name : "))
uid= int(input("Enter Your AADHAR ID PROOF (12 DIGITS) : "))
mobile= int(input("Enter Your Contact Number : +91 "))
r= int(input("Enter the Room Number you wish to book: "))
ty= eval(input("Choose the type of Room you want (Simple/Deluxe/Premium) : "))
cost(ty)
checkInDate= eval(input('Enter the Check In Date ("YYYY-MM-DD") : '))
checkOutDate= eval(input('Enter the Check Out Date ("YYYY-MM-DD") : '))
def check_out():
rno= int(input("Enter Your Room Number: "))
cur.execute("SELECT * FROM hotel WHERE room_number = %s" %(rno,))
room = cur.fetchone()
if room and room[6] == 'Occupied':
cur.execute("UPDATE hotel SET room_status = 'Vacant', id=NULL,
room_type=NULL, guest_name=NULL, contact=NULL, fee_per_day=NULL,
check_in_date=NULL, check_out_date=NULL WHERE room_number = %s", (rno,))
db.commit()
print("CHECKED OUT OF ROOM SUCCESSFULLY!")
print("THANK YOU FOR CHOOSING PYTHON HOTELS \n WE HOPE YOU VISIT US AGAIN")
def showmenu():
while True:
print("@" * 39)
print("---- WELCOME TO HOTEL PYTHON ----")
print("@" * 39)
print("Press 1 - Add a New Room")
print("Press 2 - Show All Rooms")
print("Press 3 - Show All Vacant Rooms")
print("Press 4 - Show All Occupied Rooms")
print("Press 5 - Show the types of Rooms we offer")
print("Press 6 - Book a Room")
print("Press 7 - Check Out Room")
print("Press 8 - Exit")
db.close()