-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1139 from KiranBaliga/main
Code Addition : Grocery Inventory Management Python Program
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
Beginner_Projects/Grocery Inventory Management/Grocerymanagement.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters