import mysql.
connector
# Connect to the database
cnx = [Link](
user='root',
password='Eren@mikasa',
host='localhost',
database='project'
)
cursor = [Link]()
# Function to display all items
def display_items():
[Link]("SELECT * FROM schoolbakery")
for (itemno, item, pieces, price, type) in cursor:
print(f"Item Number: {itemno}, Item: {item},
Pieces: {pieces}, Price: ₹{price}, Type: {type}")
# 1. Add or Delete Pieces
def modify_pieces():
while True:
display_items()
action = input("Do you want to add or delete
pieces? (add/delete): ").lower()
item = input("Enter the item name: ")
pieces = int(input("Enter the number of pieces:
"))
if action == "add":
[Link]("UPDATE schoolbakery SET
pieces = pieces + %s WHERE item = %s", (pieces,
item))
[Link]()
print("Pieces added successfully!")
elif action == "delete":
[Link]("UPDATE schoolbakery SET
pieces = pieces - %s WHERE item = %s", (pieces,
item))
[Link]()
print("Pieces deleted successfully!")
else:
print("Invalid action. Please enter 'add' or
'delete'.")
choice = input("Do you want to continue?
(yes/no): ")
if [Link]() != "yes":
break
# 2. Add Items to Cart and Get Total Price
def cart_checkout():
total_cost = 0
while True:
display_items()
choice = input("Do you want to add an item to
the cart? (yes/no): ").lower()
if choice != "yes":
break
item = input("Enter the item name: ")
pieces = int(input("Enter the number of pieces:
"))
[Link]("SELECT price FROM
schoolbakery WHERE item = %s", (item,))
result = [Link]()
if result:
price = result[0]
[Link]("UPDATE schoolbakery SET
pieces = pieces - %s WHERE item = %s", (pieces,
item))
[Link]()
print(f"Item: {item}, Pieces: {pieces}, Price
per piece: ₹{price}")
total_cost += pieces * price
else:
print("Item not found!")
print(f"\nTotal cost: ₹{total_cost}")
# 3. Apply Discount if Buying More Than 3 Items
def discount_cart():
cart_items = []
total_price = 0
while True:
display_items()
action = input("Do you want to add an item to
the cart? (yes/no): ").lower()
if action == "no":
break
elif action != "yes":
print("Invalid input. Please enter 'yes' or
'no'.")
continue
item = input("Enter the item name: ")
quantity = int(input("Enter the number of
pieces: "))
[Link]("SELECT price FROM
schoolbakery WHERE item = %s", (item,))
result = [Link]()
if result:
price = result[0]
cart_items.append((item, quantity, price))
total_price += quantity * price
print(f"{quantity} pieces of {item} added to
the cart.")
else:
print("Item not found!")
if len(cart_items) > 3:
total_price *= 0.8
print("You have added more than 3 items, so
you get a 20% discount.")
print("\nItems in the cart:")
for item in cart_items:
print(f"{item[0]} ({item[1]} pieces)")
print(f"\nTotal price: ₹{total_price:.2f}")
# 4. Identify Dessert Type
def identify_type():
while True:
display_items()
item = input("Enter the item name: ")
[Link]("SELECT type FROM
schoolbakery WHERE item = %s", (item,))
item_type = [Link]()
if item_type:
print(f"The type of {item} is {item_type[0]}")
else:
print("Item not found in the database.")
choice = input("Do you want to select more
items? (yes/no): ")
if [Link]() != "yes":
break
# Main Menu
def main():
while True:
print("\n--- SCHOOL BAKERY MENU ---")
print("1. Add/Delete Pieces")
print("2. Cart Checkout (Simple)")
print("3. Cart Checkout with Discount")
print("4. Identify Dessert Type")
print("5. Exit")
option = input("Select an option (1-5): ")
if option == "1":
modify_pieces()
elif option == "2":
cart_checkout()
elif option == "3":
discount_cart()
elif option == "4":
identify_type()
elif option == "5":
break
else:
print("Invalid choice. Please choose a
number between 1 and 5.")
[Link]()
[Link]()
print("Thank you! Connection closed.")
# Run the program
if __name__ == "__main__":
main()