computer project
computer project
SESSION : 2024-2025
SESSION : 2024-2025
2.DESCRIPTION Of PROJECT
4.STRUCTURE Of TaBLES
5.SOURCE CODE
6.OUTPUTS
7.BIBLIOgRaPHy
aCkNOwLEDgEMENT
: inventory
PyTHON CODE
import mysql.connector
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: ")
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: "))
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()
# 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()