Untitled
user_3592770
plain_text
2 years ago
3.3 kB
7
Indexable
# Create an empty warehouse dictionary warehouse = {} # Exchange rates for currencies relative to EUR exchange_rates = { "USD": 0.8273, "JPY": 0.0074, "CAD": 0.6581, "SEK": 0.0964 } # Function to convert prices to EUR def convert_to_eur(price, currency): if currency == "EUR": return price elif currency in exchange_rates: rate = exchange_rates[currency] return price * rate else: print(f"Unknown currency code '{currency}'. Price not converted.") return price # Function to add new products to the warehouse def add_products(): products = [] while True: name = input("Enter product name (or 'q' to quit): ") if name == "q": break price = float(input("Enter product price: ")) currency = input("Enter currency code (e.g. EUR, USD, JPY, CAD, SEK): ") converted_price = convert_to_eur(price, currency) quantity = int(input("Enter available quantity: ")) products.append((name, converted_price, quantity)) for product in products: name, price, quantity = product warehouse[name] = {"price": price, "quantity": quantity} # Function to show all available products in the warehouse def show_products(): print("Warehouse products:\n") for name, info in warehouse.items(): print(f"{name} - price: {info['price']:.2f} EUR, quantity: {info['quantity']}") # Function to remove a product from the warehouse def remove_product(name): if name in warehouse: del warehouse[name] print(f"{name} removed from warehouse.") else: print(f"Product '{name}' not found in warehouse.") # Function to update the price of an existing product def update_product_price(name, new_price): if name in warehouse: warehouse[name]['price'] = new_price print(f"Price of '{name}' updated to {new_price:.2f} EUR.") else: print(f"Product '{name}' not found in warehouse.") # Function to update the available quantity of an existing product def update_product_quantity(name, new_quantity): if name in warehouse: warehouse[name]['quantity'] = new_quantity print(f"Quantity of '{name}' updated to {new_quantity}.") else: print(f"Product '{name}' not found in warehouse.") # Add products to the warehouse entered by the user add_products() # Show all available products in the warehouse show_products() # Remove a product from the warehouse name_to_remove = input("Enter the name of the product to remove: ") remove_product(name_to_remove) # Update the price of a product in the warehouse name_to_update_price = input("Enter the name of the product to update the price: ") new_price = float(input("Enter the new price: ")) update_product_price(name_to_update_price, new_price) # Update the quantity of a product in the warehouse name_to_update_quantity = input("Enter the name of the product to update the quantity: ") new_quantity = int(input("Enter the new quantity: ")) update_product_quantity(name_to_update_quantity, new_quantity) # Show all available products in the warehouse after the updates show_products()
Editor is loading...