COMPUTER SCIENCE
PROJECT
BY:
HEMANT PAL
AND
OM SHARMA
Acknowledgement
I sincerely thank my teacher for their
guidance, support, and encouragement
throughout this project. Your insights and
feedback have been invaluable in shaping
my understanding and improving my work. I
truly appreciate your patience, dedication,
and commitment to helping me learn. This
project would not have been possible
without your support.
Sincerely,
Hemant Pal
>Write a menu driven program using list data type for
maintaining inventory control in a store :
1. Add item
[Link] item
[Link] item
4. display details of item
5. Display details of one item
6. Exit
PROGRAM :-
# Inventory Control Program
# The inventory list will store items as dictionaries.
# Each item will have an 'id', 'name', 'quantity', and 'price'.
inventory = []
def add_item():
"""Add an item to the inventory."""
try:
item_id = input("Enter item ID: ").strip()
# Check if the item id already exists.
for item in inventory:
if item['id'] == item_id:
print("Item with this ID already exists. Please
use a unique ID.")
return
name = input("Enter item name: ").strip()
quantity = int(input("Enter item quantity: "))
price = float(input("Enter item price: "))
item = {
'id': item_id,
'name': name,
'quantity': quantity,
'price': price
}
[Link](item)
print("Item added successfully!\n")
except ValueError:
print("Invalid input for quantity or price. Please try
again.\n")
def delete_item():
"""Delete an item from the inventory by its ID."""
item_id = input("Enter the ID of the item to delete:
").strip()
for index, item in enumerate(inventory):
if item['id'] == item_id:
del inventory[index]
print("Item deleted successfully!\n")
return
print("Item not found.\n")
def search_item():
"""Search for an item by its name."""
search_name = input("Enter the name of the item to
search: ").strip().lower()
found_items = [item for item in inventory if search_name
in item['name'].lower()]
if found_items:
print("Items found:")
for item in found_items:
print(f"ID: {item['id']}, Name: {item['name']},
Quantity: {item['quantity']}, Price: {item['price']}")
else:
print("No items match your search criteria.")
print()
def display_all_items():
"""Display details of all items in the inventory."""
if not inventory:
print("The inventory is empty.\n")
else:
print("Inventory details:")
for item in inventory:
print(f"ID: {item['id']}, Name: {item['name']},
Quantity: {item['quantity']}, Price: {item['price']}")
print()
def display_one_item():
"""Display details of a single item by its ID."""
item_id = input("Enter the ID of the item: ").strip()
for item in inventory:
if item['id'] == item_id:
print("Item details:")
print(f"ID: {item['id']}")
print(f"Name: {item['name']}")
print(f"Quantity: {item['quantity']}")
print(f"Price: {item['price']}\n")
return
print("Item not found.\n")
def main():
"""Main function to drive the inventory control
program."""
while True:
print("Inventory Control Menu:")
print("1. Add item")
print("2. Delete item")
print("3. Search item")
print("4. Display details of all items")
print("5. Display details of one item")
print("6. Exit")
choice = input("Enter your choice (1-6): ").strip()
if choice == '1':
add_item()
elif choice == '2':
delete_item()
elif choice == '3':
search_item()
elif choice == '4':
display_all_items()
elif choice == '5':
display_one_item()
elif choice == '6':
print("Exiting the program. Goodbye!")
break
else:
print("Invalid choice. Please try again.\n")
# Start the program
if __name__ == "__main__":
main()
OUTPUT:-
Inventory Control Menu:
1. Add item
2. Delete item
3. Search item
4. Display details of all items
5. Display details of one item
6. Exit
Enter your choice (1-6): 1
Enter item ID: 101
Enter item name: Apple
Enter item quantity: 50
Enter item price: 0.5
Item added successfully!
Inventory Control Menu:
1. Add item
2. Delete item
3. Search item
4. Display details of all items
5. Display details of one item
6. Exit
Enter your choice (1-6): 1
Enter item ID: 102
Enter item name: Banana
Enter item quantity: 100
Enter item price: 0.2
Item added successfully!
Inventory Control Menu:
1. Add item
2. Delete item
3. Search item
4. Display details of all items
5. Display details of one item
6. Exit
Enter your choice (1-6): 4
Inventory details:
ID: 101, Name: Apple, Quantity: 50, Price: 0.5
ID: 102, Name: Banana, Quantity: 100, Price: 0.2
Inventory Control Menu:
1. Add item
2. Delete item
3. Search item
4. Display details of all items
5. Display details of one item
6. Exit
Enter your choice (1-6): 3
Enter the name of the item to search: apple
Items found:
ID: 101, Name: Apple, Quantity: 50, Price: 0.5
Inventory Control Menu:
1. Add item
2. Delete item
3. Search item
4. Display details of all items
5. Display details of one item
6. Exit
Enter your choice (1-6): 2
Enter the ID of the item to delete: 102
Item deleted successfully!
Inventory Control Menu:
1. Add item
2. Delete item
3. Search item
4. Display details of all items
5. Display details of one item
6. Exit
Enter your choice (1-6): 5
Enter the ID of the item: 101
Item details:
ID: 101
Name: Apple
Quantity: 50
Price: 0.5
Inventory Control Menu:
1. Add item
2. Delete item
3. Search item
4. Display details of all items
5. Display details of one item
6. Exit
Enter your choice (1-6): 6
Exiting the program. Goodbye!