Untitled

 avatar
unknown
plain_text
2 years ago
1.0 kB
6
Indexable
#exe5_Create a function to update the price of an existing product, 
#taking as input the product name and the new price.

# Create an empty dictionary to represent the warehouse
warehouse = {}

# Input the initial products and prices in the warehouse
num_products = int(input("How many products do you want to add to the warehouse? "))
for i in range(num_products):
    product_name = input(f"Enter the name of product {i+1}: ")
    product_price = float(input(f"Enter the price of {product_name}: "))
    warehouse[product_name] = {'price': product_price, 'quantity': 0}

# Define the update_price function
def update_price():
    product_name = input("Enter the product name to update the price: ")
    if product_name in warehouse:
        new_price = float(input(f"Enter the new price for {product_name}: "))
        warehouse[product_name]['price'] = new_price
        print(f"The price of {product_name} has been updated to {new_price}.")
    else:
        print(f"{product_name} is not found in the warehouse.")
Editor is loading...