From 639e6478911f509261ccd702940eba409081285d Mon Sep 17 00:00:00 2001 From: michaelgrasshopper Date: Mon, 11 May 2026 20:27:27 +0200 Subject: [PATCH 1/2] lab-python-functions-lab3 --- lab-python-functions.ipynb | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..94986ba 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,6 +43,75 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d0cdfefa", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# 1.\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product} available in inventory: \"))\n", + " inventory[product] = quantity\n", + " return inventory\n", + "\n", + "# 2.\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " while True:\n", + " order = input(\"\\nEnter the name of a product to order (t-shirt, mug, hat, book, keychain): \").strip().lower()\n", + " \n", + " if order in products:\n", + " customer_orders.add(order)\n", + " print(f\"'{order}' has been added to your order.\")\n", + " else:\n", + " print(f\"Invalid product. Please choose from: {', '.join(products)}\")\n", + " continue\n", + "\n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break\n", + "\n", + " return customer_orders\n", + "\n", + "# 3.\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " return inventory\n", + "\n", + "# 4.\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage_ordered = (total_products_ordered / len(products)) * 100\n", + " order_statistics = (total_products_ordered, percentage_ordered)\n", + " return order_statistics\n", + "\n", + "# 5.\n", + "def print_order_statistics(order_statistics):\n", + " print(f\"\"\"\n", + "Order Statistics:\n", + "Total Products Ordered: {order_statistics[0]}\n", + "Percentage of Products Ordered: {order_statistics[1]:.2f}%\n", + " \"\"\")\n", + "\n", + "# 6.\n", + "def print_updated_inventory(inventory):\n", + " print(\"Updated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] } ], "metadata": { From 10191709876c25a6ff3ab76ba74ed40bec8ec5a5 Mon Sep 17 00:00:00 2001 From: michaelgrasshopper Date: Fri, 15 May 2026 16:11:45 +0200 Subject: [PATCH 2/2] lab-python-functions-lab-3 --- lab-python-functions.ipynb | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 94986ba..7869420 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -48,11 +48,7 @@ "cell_type": "code", "execution_count": null, "id": "d0cdfefa", - "metadata": { - "vscode": { - "languageId": "plaintext" - } - }, + "metadata": {}, "outputs": [], "source": [ "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", @@ -110,7 +106,30 @@ "def print_updated_inventory(inventory):\n", " print(\"Updated Inventory:\")\n", " for product, quantity in inventory.items():\n", - " print(f\"{product}: {quantity}\")" + " print(f\"{product}: {quantity}\")\n", + "\n", + "# 7.\n", + "# Step 1: Initialize the inventory\n", + "inventory = initialize_inventory(products)\n", + "\n", + "# Step 2: Get customer orders\n", + "customer_orders = get_customer_orders()\n", + "\n", + "# Step 3: Calculate order statistics\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "# Step 4: Print order statistics\n", + "print_order_statistics(order_statistics)\n", + "\n", + "# Step 5: Update the inventory\n", + "inventory = update_inventory(customer_orders, inventory)\n", + "\n", + "# Step 6: Print the updated inventory\n", + "print_updated_inventory(inventory)\n", + "\n", + "# Step 7: Calculate and print total price\n", + "total_price = calculate_total_price(customer_orders)\n", + "print(f\"Total Price: {total_price}\")" ] } ],