Untitled

 avatar
unknown
plain_text
2 years ago
3.3 kB
5
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.")

# Main program loop
while True:
    print("\nWhat would you like to do?")
    print("1. Add products to the warehouse")
    print("2. Show all available products in the warehouse")
    print("3. Remove a product from the warehouse")
    print("4. Update the price of a product in the warehouse")
    print("5. Update the quantity of a product in the warehouse")
    print("6. Quit the program")

    choice = input("Enter your choice (1-6): ")
    if choice == "1":
        add_products()
    elif choice == "2":
        show_products()
    elif choice == "3":
        name_to_remove = input("Enter the name of the product to remove: ")
        remove_product(name_to_remove)
    elif choice == "4":
        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
Editor is loading...