From 6686e30648cdc5e76468f18adb2a76367f875976 Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Thu, 15 Jan 2026 18:29:33 +0000 Subject: [PATCH] lab done: flow control --- lab-python-flow-control.ipynb | 102 +++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..e6bf0cc 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -14,6 +14,12 @@ "cell_type": "markdown", "id": "3851fcd1-cf98-4653-9c89-e003b7ec9400", "metadata": {}, + "source": [] + }, + { + "cell_type": "markdown", + "id": "f39aa459", + "metadata": {}, "source": [ "## Exercise: Managing Customer Orders Optimized\n", "\n", @@ -37,11 +43,103 @@ "\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": 38, + "id": "84a878f8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This product is already in your order!\n", + "{'hat', 'mug'}\n", + "{'t-shirt': 10, 'mug': 19, 'hat': 29, 'book': 40, 'keychain': 50}\n", + "Order Statistics:\n", + "Total Products Ordered:2\n", + "Percentage of Products Ordered:40.00%\n", + "Quantity of t-shirt is 10\n", + "Quantity of mug is 19\n", + "Quantity of hat is 29\n", + "Quantity of book is 40\n", + "Quantity of keychain is 50\n" + ] + } + ], + "source": [ + "#step 1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "#step 2\n", + "inventory = {}\n", + "#step 3\n", + "for product in products:\n", + " while True:\n", + " n = input(f\"Please provide the amount of {product}\")\n", + " if n.isdigit() == True:\n", + " inventory[product]= int(n)\n", + " break\n", + " else:\n", + " print(\"Please provide an acceptable number of pieces\")\n", + "\n", + "#print(inventory)\n", + "\n", + "#step 4\n", + "customer_orders = set()\n", + "#print(customer_orders)\n", + "repeat = True\n", + "\n", + "#step 5\n", + "\n", + "\n", + "while True:\n", + " prod = input(\"Please provide a product to order:\")\n", + " if prod not in products:\n", + " prod = input(\"That product is not available!\")\n", + " elif prod in customer_orders:\n", + " print(\"This product is already in your order!\")\n", + " else:\n", + " customer_orders.add(prod)\n", + " inventory[prod] -= 1\n", + " r = input(\"Do you want to order more products? (yes/no)\")\n", + " while r != \"yes\" and r != \"no\":\n", + " r = input(\"Please answer with 'yes' or 'no':\")\n", + " if r.lower() == \"no\":\n", + " break\n", + " elif r.lower() == \"yes\":\n", + " continue\n", + "\n", + "\n", + "#step 9\n", + "\n", + "#step 6\n", + "print(customer_orders)\n", + "print(inventory)\n", + "#step 7\n", + "total_prod = len(customer_orders)\n", + "perc_prod = (len(customer_orders) / len(products)) * 100\n", + "\n", + "#print(total_prod)\n", + "#print(perc_prod)\n", + "\n", + "order_status = (total_prod, perc_prod)\n", + "#type(order_status)\n", + "\n", + "#step 8\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered:{total_prod}\")\n", + "print(f\"Percentage of Products Ordered:{perc_prod:.2f}%\")\n", + "#step 10\n", + "for product in inventory:\n", + " print(f\"Quantity of {product} is {inventory[product]}\")\n", + "\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +153,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,