0% found this document useful (0 votes)
21 views4 pages

Hell

Uploaded by

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

Hell

Uploaded by

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

import mysql.

connector

db_config = ('host': 'localhost','user': 'root','password': '1234', 'database': 'cloud_kitchen')

try:

conn = mysql.connector.connect(**db_config)

cursor = conn.cursor()

print("Connected to the database.")

except mysql.connector.Error as err:

print(f"Error: {err}")

exit(1)

def show_menu():

"""Display the menu."""

cursor.execute("SELECT * FROM menu")

menu_items = cursor.fetchall()

print("\n--- Menu ---")

for item in menu_items:

print(f"{item[0]}. {item[1]} - ${item[2]:.2f}")

def add_menu_item():

"""Add a new item to the menu."""

name = input("Enter item name: ")

price = float(input("Enter item price: "))

cursor.execute("INSERT INTO menu (name, price) VALUES (%s, %s)", (name, price))

conn.commit()

print("Menu item added successfully.")

def place_order():
"""Place a new order."""

customer_name = input("Enter customer name: ")

show_menu()

menu_item_id = int(input("Enter the menu item ID: "))

quantity = int(input("Enter quantity: "))

cursor.execute("SELECT price FROM menu WHERE id = %s", (menu_item_id,))

price = cursor.fetchone()

if not price:

print("Invalid menu item ID.")

return

total_price = price[0] * quantity

cursor.execute(

"INSERT INTO orders (customer_name, menu_item_id, quantity, total_price) VALUES (%s, %s,
%s, %s)",

(customer_name, menu_item_id, quantity, total_price)

conn.commit()

print(f"Order placed successfully! Total price: ${total_price:.2f}")

def view_orders():

"""View all orders."""

cursor.execute("""

SELECT o.id, o.customer_name, m.name, o.quantity, o.total_price, o.status

FROM orders o

JOIN menu m ON o.menu_item_id = m.id

""")

orders = cursor.fetchall()

print("\n--- Orders ---")


for order in orders:

print(f"Order ID: {order[0]}, Customer: {order[1]}, Item: {order[2]}, Quantity: {order[3]}, "

f"Total: ${order[4]:.2f}, Status: {order[5]}")

def update_order_status():

"""Update the status of an order."""

view_orders()

order_id = int(input("Enter the order ID to update: "))

new_status = input("Enter new status (Pending/Completed): ")

if new_status not in ['Pending', 'Completed']:

print("Invalid status.")

return

cursor.execute("UPDATE orders SET status = %s WHERE id = %s", (new_status, order_id))

conn.commit()

print("Order status updated successfully.")

def main():

while True:

print("\n--- Cloud Kitchen Interface ---")

print("1. Show Menu")

print("2. Add Menu Item")

print("3. Place Order")

print("4. View Orders")

print("5. Update Order Status")

print("6. Exit")

choice = input("Enter your choice: ")

if choice == '1':

show_menu()

elif choice == '2':

add_menu_item()
elif choice == '3':

place_order()

elif choice == '4':

view_orders()

elif choice == '5':

update_order_status()

elif choice == '6':

print("Exiting. Goodbye!")

break

else:

print("Invalid choice. Please try again.")

if __name__ == "__main__":

main()

You might also like