You are on page 1of 2

# Grocery Store Inventory Management System

# List to store product names


products = []

# Dictionary to store product information


inventory = {}

# Function to display information about a specific product


def display_product_info(product_name):
if product_name in inventory:
print(f"Product: {product_name}")
print(f"Quantity: {inventory[product_name]['quantity']}")
print(f"Price per unit: ${inventory[product_name]['price']}")
print(f"Discount: {inventory[product_name]['discount']}%")
else:
print(f"{product_name} not found in the inventory.")

# Function to calculate the total value of the entire inventory


def calculate_total_value():
total_value = 0
for product, details in inventory.items():
total_value += details['quantity'] * details['price']
return total_value

# Function to calculate the discounted price of a product


def calculate_discounted_price(product_name, quantity, discount):
while not (0 < discount <= 100):
discount = float(input("Invalid discount percentage. Enter a valid discount (0-100%): "))

if product_name in inventory:
price_per_unit = inventory[product_name]['price']
discounted_price = price_per_unit * quantity * (1 - discount / 100)
return discounted_price
else:
return None

# Anonymous function to calculate discounted price


discount_function = lambda product_name, quantity, discount:
calculate_discounted_price(product_name, quantity, discount)

# User Inputs
product_name = input("Enter product name: ")
quantity = int(input("Enter quantity: "))
price_per_unit = float(input("Enter price per unit: "))
discount = float(input("Enter discount percentage (0-100%): "))
action = int(input("Enter action (1 to confirm, 0 to restart): "))

# List methods
products.append(product_name)
print(f"Product count: {len(products)}")
print(f"Index of {product_name}: {products.index(product_name)}")
print(f"Count of {product_name}: {products.count(product_name)}")

# Dictionary methods
inventory[product_name] = {'quantity': quantity, 'price': price_per_unit, 'discount': discount}
print(f"Keys: {list(inventory.keys())}")
print(f"Values: {list(inventory.values())}")
print(f"Items: {list(inventory.items())}")
print(f"Get quantity for {product_name}: {inventory.get(product_name, {}).get('quantity', 'Not
found')}")

# String methods
product_name_upper = product_name.upper()
product_name_lower = product_name.lower()
product_name_capitalize = product_name.capitalize()
product_name_replaced = product_name.replace("a", "X")

# Function calls
if action == 1:
display_product_info(product_name)
discounted_price = calculate_discounted_price(product_name, quantity, discount)
if discounted_price is not None:
print(f"Discounted price after {discount}% discount for {quantity} units: $
{discounted_price}")
elif action == 0:
# Restart the process or add more logic as needed
print("Restarting the process...")
else:
print("Invalid action. Please choose 1 to confirm or 0 to restart.")

You might also like