Untitled
unknown
plain_text
2 years ago
905 B
8
Indexable
# Initial inventory
inventory = [
{"product_name": "Smartphone X", "quantity": 50, "price": 500},
# ... other products
]
# Function to replace a product in the inventory
def replace_product(old_product_name, new_product):
for i, product in enumerate(inventory):
if product["product_name"] == old_product_name:
# Replace the old product with the new one
inventory[i] = new_product
print(f"{old_product_name} replaced with {new_product['product_name']} in the inventory.")
break
else:
print(f"{old_product_name} not found in the inventory.")
# New product information
new_product = {"product_name": "Smartphone X2", "quantity": 100, "price": 600}
# Replace Smartphone X with Smartphone X2
replace_product("Smartphone X", new_product)
# Updated inventory
print("Updated Inventory:")
print(inventory)Editor is loading...
Leave a Comment