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

Puthon Code Im

The document contains Python functions for managing an inventory database using SQLite. It includes functions to add, view, update, and delete products, as well as to export the inventory data to a CSV file. Each function handles database connections and operations, ensuring data integrity and providing user feedback upon completion.

Uploaded by

zubair malik
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)
0 views2 pages

Puthon Code Im

The document contains Python functions for managing an inventory database using SQLite. It includes functions to add, view, update, and delete products, as well as to export the inventory data to a CSV file. Each function handles database connections and operations, ensuring data integrity and providing user feedback upon completion.

Uploaded by

zubair malik
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

def add_product(name, quantity, price):

conn = [Link]("[Link]")

cursor = [Link]()

[Link]("INSERT INTO products (name, quantity, price) VALUES (?, ?, ?)",

(name, quantity, price))

[Link]()

[Link]()

print(f"✅ Added {name} successfully!")

def view_products():

conn = [Link]("[Link]")

cursor = [Link]()

[Link]("SELECT * FROM products")

rows = [Link]()

[Link]()

for row in rows:

print(row)

def update_quantity(product_id, new_quantity):

conn = [Link]("[Link]")

cursor = [Link]()

[Link]("UPDATE products SET quantity = ? WHERE id = ?",

(new_quantity, product_id))

[Link]()

[Link]()

print("🔄 Quantity updated!")

def delete_product(product_id):
conn = [Link]("[Link]")

cursor = [Link]()

[Link]("DELETE FROM products WHERE id = ?", (product_id,))

[Link]()

[Link]()

print("🗑️Product deleted!")

import csv

def export_to_csv(filename="inventory_report.csv"):

conn = [Link]("[Link]")

cursor = [Link]()

[Link]("SELECT * FROM products")

rows = [Link]()

[Link]()

with open(filename, "w", newline="") as file:

writer = [Link](file)

[Link](["ID", "Name", "Quantity", "Price"])

[Link](rows)

print(f"📊 Report saved as {filename}")

You might also like