0% found this document useful (0 votes)
9 views

computer project

Uploaded by

akki64891
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

computer project

Uploaded by

akki64891
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

COMPUTER SCIENCE PROJECT

SESSION : 2024-2025

PROJECT NaME : INvENTORy MaNagEMENT

NaME : PIyUSH SRIvaSTava

CLaSS : XII (PCM)

SUBMITTED TO : MR. aMIT SaXENa SIR


CHEMISTRy PROJECT

SESSION : 2024-2025

PROJECT NaME : INvENTORy MaNagEMENT

NaME : aakaSH RaJak

CLaSS : XII (PCM)

SUBMITTED TO : MR. aMIT SaXENa SIR


CONTENTS
1.aCkNOwLEDgEMENT

2.DESCRIPTION Of PROJECT

3.fUNCTIONS aND THEIR OBJECTIvES

4.STRUCTURE Of TaBLES

5.SOURCE CODE

6.OUTPUTS

7.BIBLIOgRaPHy
aCkNOwLEDgEMENT

I would like to express my deep sense of thanks


and gratitude to my teacher Mr. Amit Saxena Sir
for guiding me immensely through the course of
project. His constructive advice and constant
motivation is responsible for the successful
completion of this project. I also thank to my
parents for their motivation and support. I must
thanks to my classmates for their timely help and
support for completion of this project.
DESCRIPTION Of PROJECT
This project is designed for the management of
inventory of a grocery store. The project consists of four
options that are as follows:
1.INSERT ITEM
2.UPDATE ITEM
3.DELETE ITEM
4.FETCH INVENTORY
5.FETCH ITEM BY NAME
6.FETCH ITEM BY ID
7. EXIT THE PROGRAM
SOfTwaRE REQUIREMENT

Operating system : Windows 10/8/7


Platform : Python IDLE 3.7
Language : Python
DBMS : MySQL
HaRDwaRE REQUIREMENT

Processor : Dual Core or above


Hard Disk : 40 GB or above
RAM : 8 GB or above
fUNCTIONS aND THEIR OBJECTIvES

1.BUILT-IN fUNCTIONS aND METHODS :


a) print() : Prints the specified message to the screen.
b) input() : Reads a line entered on a console by an
input device and convert it into a string and returns
it.
c) int() : Converts the specified value in to integer
number.
d) format() : Formats the given string into a nicer
output in Python.
e) commit() : commit() method sends a commit
statement to the MySQL server, committing the
current transaction.
2. USER DEfINED fUNCTIONS :
a) create_table_if_not_exist(conn): For creating
table if it doesn’t exist.
b) insert_item(conn): To insert new item in the
table.
c) update_item(conn): To update existing item in
the table.
d) delete_item(conn): To delete existing item in
the table.
e) fetch_inventory(conn): To fetch the inventory
as whole.
f) fetch_item_by_name(conn): To the fetch item
by name from the table.
g) fetch_item_by_id(conn): To fetch the item by
id from the table.
STRUCTURE Of TaBLES
DBMS: MySQL
Host : localhost
User: root
Pass: skd123
DataBase :
Table structure : As given below
Table

: inventory
PyTHON CODE
import mysql.connector

# Function to connect to MySQL database (directly to


grocery_store)
def connect_to_database():
return mysql.connector.connect(
host='localhost',
user='root',
password='iambatman',
database='grocery_store'
)

# Function to create the database if it doesn't exist


def create_database():
conn = mysql.connector.connect(
host='localhost',
user='root',
password='iambatman'
)
cursor = conn.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS
grocery_store")
cursor.close()
conn.close()

# Function to create table if it doesn't exist


def create_table_if_not_exists(conn):
cursor = conn.cursor()
create_table_query = """
CREATE TABLE IF NOT EXISTS inventory (
id INT AUTO_INCREMENT PRIMARY KEY,
item_name VARCHAR(255),
item_price FLOAT,
item_quantity INT
);
"""
cursor.execute(create_table_query)
cursor.close()
# Function to insert new data into the table
def insert_item(conn):
cursor = conn.cursor()
item_name = input("Enter the name of the item: ")
item_price = float(input("Enter the price of the item:
"))
item_quantity = int(input("Enter the quantity of the
item: "))
cursor.execute(
"INSERT INTO inventory (item_name, item_price,
item_quantity) VALUES (%s, %s, %s)",
(item_name, item_price, item_quantity)
)
conn.commit()
print(f"{item_quantity} {item_name}(s) added to the
inventory.")
cursor.close()

# Function to update an item in the table


def update_item(conn):
cursor = conn.cursor()
item_id = int(input("Enter the ID of the item to
update: "))
new_price = float(input("Enter the new price: "))
new_quantity = int(input("Enter the new quantity: "))
cursor.execute(
"UPDATE inventory SET item_price = %s,
item_quantity = %s WHERE id = %s",
(new_price, new_quantity, item_id)
)
conn.commit()
print("Item updated.")
cursor.close()

# Function to delete an item from the table


def delete_item(conn):
cursor = conn.cursor()
item_id = int(input("Enter the ID of the item to
delete: "))
cursor.execute("DELETE FROM inventory WHERE id =
%s", (item_id,))
conn.commit()
print("Item deleted.")
cursor.close()

# Function to fetch and display all items from the table


def fetch_inventory(conn):
cursor = conn.cursor()
cursor.execute("SELECT * FROM inventory")
result = cursor.fetchall()
if len(result) == 0:
print("No items in the inventory.")
else:

print("Current Inventory: ")

print("________________________________________
_____________________________")
print("|ID: \t|","Name\t\t|","Price\t\t|","Quantity|")

print("________________________________________
_____________________________")
for row in result:
if len(row[1])>4:
t="\t|"
else:
t="\t"*2
print(row[0],"\t|",row[1],"\t\t|", row[2],"\t\t|",
row[3],"\t|")
cursor.close()
def fetch_item_by_name(conn):
cursor = conn.cursor()
nm = input("Enter item name to search: ")

# Execute a query to find the item by name directly


cursor.execute("SELECT * FROM inventory WHERE
item_name = %s", (nm,))
result = cursor.fetchall()

# Check if the result is empty


if result:
print("________________________________________
_____________________________")
print("| ID | Name | Price |
Quantity |")

print("________________________________________
_____________________________")
for row in result:
print(row[0],"\t|",row[1],"\t\t|", row[2],"\t\t|",
row[3],"\t|")

print("________________________________________
_____________________________")
else:
print("Item not found!")

cursor.close()

def fetch_item_by_id(conn):
cursor = conn.cursor()
id = int(input("Enter id no. to be searched: "))

# Fetch the specific item by id


cursor.execute("SELECT * FROM inventory WHERE id
= %s", (id,))
row = cursor.fetchone()

if row:

print("________________________________________
_____________________________")
print("|ID: \t|","Name\t\t|","Price\t\t|","Quantity|")

print("________________________________________
_____________________________")
print(row[0],"\t|",row[1],"\t\t|", row[2],"\t\t|",
row[3],"\t|")

print("________________________________________
_____________________________")
else:
print("Item not found")
cursor.close()

# Main function
def main():
# Step 1: Create the database if it doesn't exist
create_database()

# Step 2: Connect to the grocery_store database


conn = connect_to_database()

# Step 3: Create the inventory table if it doesn't exist


create_table_if_not_exists(conn)

# Menu system
while True:
print("\nWhat would you like to do?")
print("1. Insert a new item")
print("2. Update an item")
print("3. Delete an item")
print("4. Fetch the inventory")
print("5. Search item by name")
print("6. Search item by ID")
print("7. Exit")
choice = input("Enter your choice (1-5): ")

if choice == '1':
insert_item(conn)
elif choice == '2':
update_item(conn)
elif choice == '3':
delete_item(conn)
elif choice == '4':
fetch_inventory(conn)
elif choice == '5':
fetch_item_by_name(conn)
elif choice == '6':
fetch_item_by_id(conn)
elif choice == '7':
print("Exiting the program.")
break
else:
print("Invalid choice. Please try again.")

conn.close()

# Run the main function


if __name__ == "__main__":
main()
OUTPUTS
BIBLIOgRaPHy

• Computer science with Python by Sumita Arora class XII


• Computer science NCERT textbook for class XII
• www.wikipedia.org
• Under the guidance of subject teacher

You might also like