Programming
Programming
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
# 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.")