From 77feefaf31cf8374691d513228648e264ce29664 Mon Sep 17 00:00:00 2001 From: Radovan Wilczek Date: Wed, 18 Feb 2026 16:07:19 +0100 Subject: [PATCH 1/3] Copied data from Lab day 1 --- lab-python-flow-control.ipynb | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..377b139 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,56 @@ "\n", "3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")." ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "885278bf", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "\n", + "print(\"Inventory:\", inventory)\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}:\"))\n", + " inventory[product] = quantity \n", + " inventory_total = sum(inventory.values()) \n", + " print(inventory) \n", + "print(\"Inventory:\", inventory)\n", + "customer_orders = set()\n", + "\n", + "print(inventory_total)\n", + "\n", + "while len(customer_orders) < 3:\n", + " order = input(\"Enter a product to order:\")\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " inventory_total -= 1\n", + " inventory[order] -= 1\n", + " else:\n", + " print(\"Invalid product. Please choose from the available products.\")\n", + "print(\"Customer orders:\", customer_orders)\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "\n", + "\n", + "\n", + "\n", + "print(\"Order statistics:\")\n", + "print(\"Total products ordered:\", total_products_ordered)\n", + "percentage_ordered = (total_products_ordered / inventory_total) * 100\n", + "print(\"Percentage of products ordered:\", f\"{percentage_ordered:.2f}%\")\n", + "\n", + "for item, qty in inventory.items():\n", + " print(f\"{item}: {qty} remaining\")" + ] } ], "metadata": { From d38a0f4b2fc85bdb7e59cda00fd6dd3e8642e51f Mon Sep 17 00:00:00 2001 From: Radovan Wilczek Date: Wed, 18 Feb 2026 16:29:24 +0100 Subject: [PATCH 2/3] Tasks completed --- lab-python-flow-control.ipynb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 377b139..84e9f80 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -60,14 +60,18 @@ " inventory_total = sum(inventory.values()) \n", " print(inventory) \n", "print(\"Inventory:\", inventory)\n", - "customer_orders = set()\n", + "\n", "\n", "print(inventory_total)\n", "\n", + "#2 Prompt the user to enter the name of a product\n", + "\n", + "customer_orders = set() \n", + "\n", "while len(customer_orders) < 3:\n", " order = input(\"Enter a product to order:\")\n", " if order in products:\n", - " customer_orders.add(order)\n", + " customer_orders.add(order) #a add the product name to the customer_orders set\n", " inventory_total -= 1\n", " inventory[order] -= 1\n", " else:\n", From ef2f02eb6ee5f24db2eafc62ec11939956f0c036 Mon Sep 17 00:00:00 2001 From: Radovan Wilczek Date: Wed, 18 Feb 2026 16:32:38 +0100 Subject: [PATCH 3/3] Final version of solution --- lab-python-flow-control.ipynb | 51 ++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 84e9f80..4a7314c 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -42,12 +42,35 @@ "cell_type": "code", "execution_count": null, "id": "885278bf", - "metadata": { - "vscode": { - "languageId": "plaintext" + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {}\n", + "{'t-shirt': 10}\n", + "{'t-shirt': 10, 'mug': 10}\n", + "{'t-shirt': 10, 'mug': 10, 'hat': 10}\n", + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10}\n", + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n", + "Inventory: {'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n", + "50\n", + "Invalid product. Please choose from the available products.\n", + "Invalid product. Please choose from the available products.\n", + "Invalid product. Please choose from the available products.\n", + "Customer orders: {'keychain', 'mug'}\n", + "Order statistics:\n", + "Total products ordered: 2\n", + "Percentage of products ordered: 4.17%\n", + "t-shirt: 10 remaining\n", + "mug: 9 remaining\n", + "hat: 10 remaining\n", + "book: 10 remaining\n", + "keychain: 9 remaining\n" + ] } - }, - "outputs": [], + ], "source": [ "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", "inventory = {}\n", @@ -66,14 +89,18 @@ "\n", "#2 Prompt the user to enter the name of a product\n", "\n", - "customer_orders = set() \n", + "customer_orders = set()\n", + "another_product = True \n", "\n", - "while len(customer_orders) < 3:\n", - " order = input(\"Enter a product to order:\")\n", + "while another_product != False:\n", + " order = input(\"Enter a product to order:\") #a prompt the user to enter the name of a product\n", " if order in products:\n", - " customer_orders.add(order) #a add the product name to the customer_orders set\n", + " customer_orders.add(order) #b add the product name to the customer_orders set\n", " inventory_total -= 1\n", - " inventory[order] -= 1\n", + " inventory[order] -= 1 #3 substract only products that are ordered from the inventory\n", + " another_product_input = input(\"Do you want to order another product? (Yes/No):\") #c ask the user if they want to order another product\n", + " if another_product_input.lower() == \"no\": #d continue to prompt the user until they indicate that they do not want to order another product\n", + " another_product = False\n", " else:\n", " print(\"Invalid product. Please choose from the available products.\")\n", "print(\"Customer orders:\", customer_orders)\n", @@ -95,7 +122,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -109,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.3" } }, "nbformat": 4,