0% found this document useful (0 votes)
17 views2 pages

Hotel

Uploaded by

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

Hotel

Uploaded by

pramod kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import sqlite3

import datetime

# Create a SQLite database and establish a connection


conn = sqlite3.connect("hotel.db")
cursor = conn.cursor()

# Create tables for rooms and reservations


cursor.execute('''CREATE TABLE IF NOT EXISTS rooms
(room_number INT PRIMARY KEY,
room_type TEXT,
price REAL,
status TEXT)''')

cursor.execute('''CREATE TABLE IF NOT EXISTS reservations


(reservation_id INTEGER PRIMARY KEY,
room_number INT,
guest_name TEXT,
check_in_date DATE,
check_out_date DATE,
total_cost REAL)''')

# Sample data for rooms (you can populate this with real data)
cursor.executemany('INSERT INTO rooms VALUES (?,?,?,?)',
[(101, 'Single', 100.0, 'Vacant'),
(102, 'Double', 150.0, 'Vacant'),
(103, 'Suite', 200.0, 'Vacant')])

# Function to display available rooms


def display_available_rooms():
cursor.execute('SELECT * FROM rooms WHERE status="Vacant"')
available_rooms = cursor.fetchall()
if not available_rooms:
print("No rooms are currently available.")
else:
print("Available Rooms:")
for room in available_rooms:
print(f"Room Number: {room[0]}, Type: {room[1]}, Price: ${room[2]}")

# Function to book a room


def book_room(room_number, guest_name, check_in_date, check_out_date):
cursor.execute('SELECT price FROM rooms WHERE room_number=?', (room_number,))
room_price = cursor.fetchone()[0]
total_cost = room_price * (check_out_date - check_in_date).days

cursor.execute('INSERT INTO reservations (room_number, guest_name,


check_in_date, check_out_date, total_cost) VALUES (?,?,?,?,?)',
(room_number, guest_name, check_in_date, check_out_date,
total_cost))

cursor.execute('UPDATE rooms SET status="Occupied" WHERE room_number=?',


(room_number,))
conn.commit()
print(f"Room {room_number} has been booked. Total Cost: ${total_cost}")

# Main menu
while True:
print("\nHotel Management System")
print("1. Display Available Rooms")
print("2. Book a Room")
print("3. Exit")
choice = input("Enter your choice: ")

if choice == '1':
display_available_rooms()
elif choice == '2':
room_number = int(input("Enter the room number: "))
guest_name = input("Enter guest name: ")
check_in_date = datetime.datetime.strptime(input("Check-in date (YYYY-MM-
DD): "), '%Y-%m-%d').date()
check_out_date = datetime.datetime.strptime(input("Check-out date (YYYY-MM-
DD): "), '%Y-%m-%d').date()
book_room(room_number, guest_name, check_in_date, check_out_date)
elif choice == '3':
break

# Close the database connection when done


conn.close()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy