***MySQL*** mysql> USE grocery_db; Database changed mysql> mysql> CREATE TABLE products ( -> id INT AUTO_INCREMENT PRIMARY KEY, -> name VARCHAR(100) NOT NULL, -> price DECIMAL(10,2) NOT NULL, -> quantity INT NOT NULL -> ); Query OK, 0 rows affected (1.54 sec) mysql> select*from grocery_db; ERROR 1146 (42S02): Table 'grocery_db.grocery_db' doesn't exist mysql> select*from products; +----+-------+-------+----------+ | id | name | price | quantity | +----+-------+-------+----------+ | 1 | Egg | 10.00 | 12 | | 2 | Rice | 60.00 | 50 | | 3 | sugar | 45.00 | 27 | | 4 | Bread | 40.00 | 15 | +----+-------+-------+----------+ 4 rows in set (0.00 sec) ***source code*** import mysql.connector # Connect to MySQL db = mysql.connector.connect( host="localhost", user="root", password="admin", database="grocery_db", use_pure=True ) cursor = db.cursor() def add_product(): name = input("Enter product name: ") price = float(input("Enter price: ")) quantity = int(input("Enter quantity: ")) sql = "INSERT INTO products (name, price, quantity) VALUES (%s, %s, %s)" values = (name, price, quantity) cursor.execute(sql, values) db.commit() print("Product added successfully!") def view_products(): cursor.execute("SELECT * FROM products") products = cursor.fetchall() print("\nID | Name | Price | Quantity") print("-" * 35) for product in products: print(product) def sell_product(): product_id = int(input("Enter product ID: ")) sell_quantity = int(input("Enter quantity to sell: ")) cursor.execute( "SELECT name, price, quantity FROM products WHERE id = %s", (product_id,) ) product = cursor.fetchone() if product is None: print("Product not found!") return name, price, stock = product if sell_quantity > stock: print("Not enough stock!") return new_stock = stock - sell_quantity cursor.execute( "UPDATE products SET quantity = %s WHERE id = %s", (new_stock, product_id) ) db.commit() total = price * sell_quantity print("\nSale successful!") print("Product:", name) print("Quantity:", sell_quantity) print("Total price: ₹", total) def main(): while True: print("\n===== GROCERY MANAGEMENT SYSTEM =====") print("1. Add Product") print("2. View Products") print("3. Sell Product") print("4. Exit") choice = input("Enter your choice: ") if choice == "1": add_product() elif choice == "2": view_products() elif choice == "3": sell_product() elif choice == "4": print("Thank you!") break else: print("Invalid choice!") main() cursor.close() db.close() ***output*** == RESTART: C:/Users/sgps/AppData/Local/Programs/Python/ Python313/groc pjc.py == ===== GROCERY MANAGEMENT SYSTEM ===== 1. Add Product 2. View Products 3. Sell Product 4. Exit Enter your choice: 1 Enter product name: Egg Enter price: 10 Enter quantity: 12 Product added successfully! ===== GROCERY MANAGEMENT SYSTEM ===== 1. Add Product 2. View Products 3. Sell Product 4. Exit Enter your choice: 1 Enter product name: Rice Enter price: 60 Enter quantity: 50 Product added successfully! ===== GROCERY MANAGEMENT SYSTEM ===== 1. Add Product 2. View Products 3. Sell Product 4. Exit Enter your choice: 1 Enter product name: sugar Enter price: 45 Enter quantity: 30 Product added successfully! ===== GROCERY MANAGEMENT SYSTEM ===== 1. Add Product 2. View Products 3. Sell Product 4. Exit Enter your choice: 1 Enter product name: Bread Enter price: 40 Enter quantity: 15 Product added successfully! ===== GROCERY MANAGEMENT SYSTEM ===== 1. Add Product 2. View Products 3. Sell Product 4. Exit Enter your choice: 2 ID | Name | Price | Quantity ----------------------------------- (1, 'Egg', Decimal('10.00'), 12) (2, 'Rice', Decimal('60.00'), 50) (3, 'sugar', Decimal('45.00'), 30) (4, 'Bread', Decimal('40.00'), 15) ===== GROCERY MANAGEMENT SYSTEM ===== 1. Add Product 2. View Products 3. Sell Product 4. Exit Enter your choice: 3 Enter product ID: 3 Enter quantity to sell: 3 Sale successful! Product: sugar Quantity: 3 Total price: ₹ 135.00 ===== GROCERY MANAGEMENT SYSTEM ===== 1. Add Product 2. View Products 3. Sell Product 4. Exit Enter your choice: