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

import pandas as pd

This document outlines a Python script for a Grocery Shop Management System using pandas to manage inventory. It includes functions to add items, update quantities, view inventory, and generate bills based on customer purchases. The script provides a command-line interface for user interaction to perform these operations.

Uploaded by

piyusharyanjee1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

import pandas as pd

This document outlines a Python script for a Grocery Shop Management System using pandas to manage inventory. It includes functions to add items, update quantities, view inventory, and generate bills based on customer purchases. The script provides a command-line interface for user interaction to perform these operations.

Uploaded by

piyusharyanjee1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import pandas as pd

# Initialize the inventory as a DataFrame


inventory = pd.DataFrame(columns=['Item ID', 'Name', 'Price', 'Quantity'])

# Function to add a new item to the inventory


def add_item(item_id, name, price, quantity):
global inventory
inventory = pd.concat([
inventory,
pd.DataFrame({'Item ID': [item_id], 'Name': [name], 'Price': [price],
'Quantity': [quantity]})
], ignore_index=True)
print(f"Item '{name}' added successfully!")

# Function to update item quantity


def update_quantity(item_id, quantity):
global inventory
if item_id in inventory['Item ID'].values:
inventory.loc[inventory['Item ID'] == item_id, 'Quantity'] += quantity
print(f"Quantity updated for Item ID {item_id}.")
else:
print(f"Item ID {item_id} not found in inventory.")

# Function to view the inventory


def view_inventory():
global inventory
if inventory.empty:
print("The inventory is empty.")
else:
print(inventory)

# Function to generate a bill


def generate_bill(items):
global inventory
total = 0
bill_items = []

for item_id, quantity in items.items():


if item_id in inventory['Item ID'].values:
item = inventory[inventory['Item ID'] == item_id]
available_qty = item['Quantity'].values[0]
if quantity <= available_qty:
cost = item['Price'].values[0] * quantity
total += cost
bill_items.append({
'Item ID': item_id,
'Name': item['Name'].values[0],
'Price': item['Price'].values[0],
'Quantity': quantity,
'Total': cost
})
inventory.loc[inventory['Item ID'] == item_id, 'Quantity'] -=
quantity
else:
print(f"Insufficient stock for Item ID {item_id}. Available:
{available_qty}.")
else:
print(f"Item ID {item_id} not found in inventory.")
bill_df = pd.DataFrame(bill_items)
print("\n--- Bill ---")
print(bill_df)
print(f"Total Amount: {total}")

# Example usage
if __name__ == "__main__":
while True:
print("\nGrocery Shop Management System")
print("1. Add Item")
print("2. Update Quantity")
print("3. View Inventory")
print("4. Generate Bill")
print("5. Exit")

choice = input("Enter your choice: ")

if choice == '1':
item_id = input("Enter Item ID: ")
name = input("Enter Item Name: ")
price = float(input("Enter Item Price: "))
quantity = int(input("Enter Quantity: "))
add_item(item_id, name, price, quantity)

elif choice == '2':


item_id = input("Enter Item ID: ")
quantity = int(input("Enter Quantity to Add: "))
update_quantity(item_id, quantity)

elif choice == '3':


view_inventory()

elif choice == '4':


items = {}
print("Enter items to purchase (Item ID and Quantity). Type 'done' to
finish.")
while True:
item_id = input("Enter Item ID: ")
if item_id.lower() == 'done':
break
quantity = int(input("Enter Quantity: "))
items[item_id] = quantity

generate_bill(items)

elif choice == '5':


print("Exiting...")
break

else:
print("Invalid choice. Please try again.")

You might also like