Untitled
user_3592770
plain_text
3 years ago
3.4 kB
10
Indexable
# exe4_Create a function to add a new product to the warehouse,
# taking as input the product name, the price, and the quantity.
def add_product():
product_name = input("Enter the name of the new product: ")
if product_name in warehouse:
print(f"{product_name} already exists in the warehouse.")
else:
product_price = float(input("Enter the price of the new product (in EUR): "))
product_currency = input("Enter the currency of the price: ")
product_quantity = int(input("Enter the quantity of the new product: "))
warehouse[product_name] = {'price': convert_to_eur(product_price, product_currency), 'quantity': product_quantity}
print(f"{product_name} has been added to the warehouse.")
#exe5_Create a function to update the price of an existing product,
#taking as input the product name and the new price.
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} (in EUR): "))
new_currency = input("Enter the currency of the new price: ")
warehouse[product_name]['price'] = convert_to_eur(new_price, new_currency)
print(f"The price of {product_name} has been updated to {new_price} {new_currency}.")
else:
print(f"{product_name} is not found in the warehouse.")
#exe6_Create a function to update the available quantity of an
#existing product, taking as input the product name and the
#new available quantity.
def update_quantity():
product_name = input("Enter the product name to update the quantity: ")
if product_name in warehouse:
new_quantity = int(input("Enter the new quantity: "))
warehouse[product_name]['quantity'] = new_quantity
print(f"The quantity of {product_name} has been updated to {new_quantity}.")
else:
print(f"{product_name} is not found in the warehouse.")
#exe7_Create a function to search for a product in the
#warehouse, taking as input the product name and
#returning the price and available quantity.
def search_product():
product_name = input("Enter the name of the product to search for: ")
if product_name in warehouse:
price = warehouse[product_name]['price']
quantity = warehouse[product_name]['quantity']
print(f"The price of {product_name} is {price} EUR and the available quantity is {quantity}.")
else:
print(f"{product_name} is not found in the warehouse.")
# Define a function to convert price from different currencies to EUR
def convert_to_eur(price, currency):
# Conversion rates for some currencies
if currency == 'EUR':
return price
elif currency == 'USD':
return price * 0.85
elif currency == 'CAD':
return price * 0.68
elif currency == 'JPY':
return price * 0.0078
elif currency == 'SEK':
return price * 0.10
else:
raise ValueError('Unsupported currency')
# 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)
Editor is loading...