0% found this document useful (0 votes)
11 views5 pages

conn

The document outlines a Python script for managing bookings and food orders in a database. It includes functions to add booking records, view all bookings, and order food, with details on how to insert records into the Bookings and FoodOrders tables. The script also retrieves available food items and calculates the total cost for food orders based on user input.

Uploaded by

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

conn

The document outlines a Python script for managing bookings and food orders in a database. It includes functions to add booking records, view all bookings, and order food, with details on how to insert records into the Bookings and FoodOrders tables. The script also retrieves available food items and calculates the total cost for food orders based on user input.

Uploaded by

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

conn.

commit()

# Add booking record


booking_time = datetime.now()
cursor.execute()
"INSERT INTO Bookings (RoomID,
CustomerName, SeatsBooked, BookingTime)
VALUES (%s, %s, %s, %s)",
(room_id, customer_name, seats,
booking_time)

conn.commit()
print("Booking confirmed!")

cursor.close()
conn.close()

# Function to view all bookings


def view_bookings():
conn = connect_db()
cursor = conn.cursor()

# Fetch and display bookings


cursor.execute("SELECT * FROM Bookings")
bookings = cursor.fetchall()
print("Bookings:")
for booking in bookings:
print(f"Booking ID: {booking[0]}, Room
ID: {booking[1]}, Customer: {booking[2]},
Seats: {booking[3]}, Time: {booking[4]}")

cursor.close()
conn.close()

# Function to order food and store each order


in the FoodOrders table
def order_food():
conn = connect_db()
cursor = conn.cursor()

# Display available food items


cursor.execute("SELECT * FROM
FoodItems")
foods = cursor.fetchall()
print("Available food items:")
for food in foods:
print(f"Food ID: {food[0]}, Name:
{food[1]}, Price: ${food[2]:.2f}")

# Retrieve booking ID for food order


association
booking_id = int(input("Enter your Booking
ID: "))

# Order food item


food_id = int(input("Enter the Food ID you
want to order: "))
quantity = int(input("Enter the quantity: "))

# Get the price of the selected food item


cursor.execute("SELECT Price FROM
FoodItems WHERE FoodID = %s", (food_id,))
price = cursor.fetchone()[0]
total_cost = price * quantity
print(f"Total cost for {quantity} items: $
{total_cost:.2f}")

# Store the order in FoodOrders table


cursor.execute()
"INSERT INTO FoodOrders (BookingID,
FoodID, Quantity, TotalCost) VALUES (%s, %s,
%s, %s)",
(booking_id, food_id, quantity, total_cost)
conn.commit()
print("Food order recorded successfully!")

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