Skip to content

Commit

Permalink
Merge pull request #1139 from KiranBaliga/main
Browse files Browse the repository at this point in the history
Code Addition : Grocery Inventory Management Python Program
  • Loading branch information
UTSAVS26 authored Jan 9, 2025
2 parents ba08ff4 + 0519eae commit b31eed1
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Simple Grocery Inventory Management

inventory = {}

def add_item():
item_name = input("Enter the name of the item: ").strip().capitalize()
if item_name in inventory:
print(f"{item_name} already exists. Updating quantity.")
inventory[item_name] += int(input("Enter the quantity to add: "))
else:
quantity = int(input("Enter the quantity: "))
price = float(input("Enter the price per unit: "))
inventory[item_name] = {"quantity": quantity, "price": price}
print(f"{item_name} has been added/updated.")

def view_inventory():
if not inventory:
print("The inventory is empty.")
return
print("\nCurrent Inventory:")
print(f"{'Item':<15}{'Quantity':<10}{'Price/Unit':<10}")
print("-" * 35)
for item, details in inventory.items():
print(f"{item:<15}{details['quantity']:<10}{details['price']:<10.2f}")
print()

def update_item():
item_name = input("Enter the name of the item to update: ").strip().capitalize()
if item_name in inventory:
quantity = int(input("Enter the new quantity: "))
price = float(input("Enter the new price per unit: "))
inventory[item_name] = {"quantity": quantity, "price": price}
print(f"{item_name} has been updated.")
else:
print(f"{item_name} does not exist in the inventory.")

def delete_item():
item_name = input("Enter the name of the item to delete: ").strip().capitalize()
if item_name in inventory:
del inventory[item_name]
print(f"{item_name} has been deleted.")
else:
print(f"{item_name} does not exist in the inventory.")

def main():
while True:
print("\nGrocery Inventory Management")
print("1. Add Item")
print("2. View Inventory")
print("3. Update Item")
print("4. Delete Item")
print("5. Exit")
choice = input("Enter your choice: ").strip()

if choice == '1':
add_item()
elif choice == '2':
view_inventory()
elif choice == '3':
update_item()
elif choice == '4':
delete_item()
elif choice == '5':
print("Exiting the program. Goodbye!")
break
else:
print("Invalid choice. Please try again.")

if __name__ == "__main__":
main()
32 changes: 32 additions & 0 deletions Beginner_Projects/Grocery Inventory Management/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Grocery Inventory Management

A simple Python program to manage a grocery inventory. This program allows you to add items, view the inventory, update item details, and delete items through a user-friendly menu.

---

## Features
1. **Add Item**
- Add new items to the inventory or update the quantity of an existing item.
- Includes input for item quantity and price per unit.

2. **View Inventory**
- Display all items in the inventory with their quantity and price per unit.

3. **Update Item**
- Modify the quantity and price of an existing item.

4. **Delete Item**
- Remove an item from the inventory.

5. **Exit Program**
- Exit the program safely.

---

## How to Use
1. Clone or download this repository to your local machine.
2. Ensure you have Python 3 installed on your system.
3. Open a terminal or command prompt in the program directory.
4. Run the script with the following command:
```bash
python inventory.py
2 changes: 2 additions & 0 deletions Project-Structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@
* [Example](Beginner_Projects/File%20Sorter/Theme/example.py)
* Financial Ai Assistant
* [Main](Beginner_Projects/Financial%20AI%20Assistant/main.py)
* Grocery Inventory Management
* [Grocerymanagement](Beginner_Projects/Grocery%20Inventory%20Management/Grocerymanagement.py)
* Morse Code Translator With Gui
* [Main](Beginner_Projects/Morse%20Code%20Translator%20with%20GUI/main.py)
* Number Guessing Game
Expand Down

0 comments on commit b31eed1

Please sign in to comment.