From c55ebca523d764da77c309b3bbb08baf541a7fb2 Mon Sep 17 00:00:00 2001 From: salvadorciaurriz-lang Date: Tue, 14 Apr 2026 13:00:41 +0200 Subject: [PATCH 1/2] Update lab-python-flow-control.ipynb flow control 1.0 --- lab-python-flow-control.ipynb | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..31ff0a2 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -35,7 +35,37 @@ " \n", " d. Continue the loop until the user does not want to add another product.\n", "\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\")." + "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\").\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "for product in products:\n", + " quantity = int(input(f\"Enter quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " product = input(\"Enter a product name: \").lower()\n", + " customer_orders.add(product)\n", + " \n", + " another = input(\"Do you want to add another product? (yes/no): \").lower()\n", + " if another != \"yes\":\n", + " break\n", + "\n", + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + "\n", + "total_orders = len(customer_orders)\n", + "percentage = (total_orders / len(products)) * 100\n", + "\n", + "print(f\"Total unique products ordered: {total_orders}\")\n", + "print(f\"Percentage of products ordered: {percentage:.2f}%\")\n", + "\n", + "print(\"Updated inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" ] } ], From 9e99304e607357ef04db05550cda269b6017a4a2 Mon Sep 17 00:00:00 2001 From: salvadorciaurriz-lang Date: Tue, 14 Apr 2026 14:38:13 +0200 Subject: [PATCH 2/2] Update lab-python-flow-control.ipynb flow control 2 --- lab-python-flow-control.ipynb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 31ff0a2..0e02e70 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -47,25 +47,31 @@ "\n", "while True:\n", " product = input(\"Enter a product name: \").lower()\n", - " customer_orders.add(product)\n", + " \n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Product not available. Please choose from the list.\")\n", + " continue\n", " \n", " another = input(\"Do you want to add another product? (yes/no): \").lower()\n", " if another != \"yes\":\n", " break\n", "\n", "for product in customer_orders:\n", - " if product in inventory:\n", - " inventory[product] -= 1\n", + " inventory[product] -= 1\n", + "\n", + "total_unique_orders = len(customer_orders)\n", + "percentage_unique_orders = (total_unique_orders / len(products)) * 100\n", "\n", - "total_orders = len(customer_orders)\n", - "percentage = (total_orders / len(products)) * 100\n", + "print(f\"Total unique products ordered: {total_unique_orders}\")\n", + "print(f\"Percentage of unique products ordered: {percentage_unique_orders:.2f}%\")\n", "\n", - "print(f\"Total unique products ordered: {total_orders}\")\n", - "print(f\"Percentage of products ordered: {percentage:.2f}%\")\n", + "print(\"Customer orders:\", customer_orders)\n", "\n", "print(\"Updated inventory:\")\n", "for product, quantity in inventory.items():\n", - " print(f\"{product}: {quantity}\")" + " print(f\"{product}: {quantity}\")\n" ] } ],