From 2ae4d631fd3b62c9c82b0a7cf7995e8ac992a01d Mon Sep 17 00:00:00 2001 From: Jan Noel Vero Date: Wed, 22 Jul 2026 15:33:08 +0200 Subject: [PATCH 1/3] lab-python-flow-control --- lab-python-flow-control.ipynb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..c4862c0 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -13,7 +13,9 @@ { "cell_type": "markdown", "id": "3851fcd1-cf98-4653-9c89-e003b7ec9400", - "metadata": {}, + "metadata": { + "jp-MarkdownHeadingCollapsed": true + }, "source": [ "## Exercise: Managing Customer Orders Optimized\n", "\n", @@ -55,7 +57,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.14" } }, "nbformat": 4, From 707afef8b6f93d36449aac586450ba4ca048daf5 Mon Sep 17 00:00:00 2001 From: Jan Noel Vero Date: Wed, 22 Jul 2026 15:35:59 +0200 Subject: [PATCH 2/3] Complete customer orders exercise --- .../lab-python-flow-control-checkpoint.ipynb | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .ipynb_checkpoints/lab-python-flow-control-checkpoint.ipynb diff --git a/.ipynb_checkpoints/lab-python-flow-control-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-flow-control-checkpoint.ipynb new file mode 100644 index 0000000..f4c7391 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-flow-control-checkpoint.ipynb @@ -0,0 +1,63 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d3bfc191-8885-42ee-b0a0-bbab867c6f9f", + "metadata": { + "tags": [] + }, + "source": [ + "# Lab | Flow Control" + ] + }, + { + "cell_type": "markdown", + "id": "3851fcd1-cf98-4653-9c89-e003b7ec9400", + "metadata": {}, + "source": [ + "## Exercise: Managing Customer Orders Optimized\n", + "\n", + "In the last lab, you were starting an online store that sells various products. To ensure smooth operations, you developed a program that manages customer orders and inventory.\n", + "\n", + "You did so without using flow control. Let's go a step further and improve this code.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "1. Look at your code from the lab data structures, and improve repeated code with loops.\n", + "\n", + "2. Instead of asking the user to input the name of three products that a customer wants to order, do the following:\n", + " \n", + " a. Prompt the user to enter the name of a product that a customer wants to order.\n", + " \n", + " b. Add the product name to the \"customer_orders\" set.\n", + " \n", + " c. Ask the user if they want to add another product (yes/no).\n", + " \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\")." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 57206fe483e43b68513569c44528db6621b47f0c Mon Sep 17 00:00:00 2001 From: Jan Noel Vero Date: Fri, 24 Jul 2026 09:43:40 +0200 Subject: [PATCH 3/3] Complete lab-python-flow-control --- .../lab-python-flow-control-checkpoint.ipynb | 114 ++++++++++++++++- lab-python-flow-control.ipynb | 116 +++++++++++++++++- 2 files changed, 226 insertions(+), 4 deletions(-) diff --git a/.ipynb_checkpoints/lab-python-flow-control-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-flow-control-checkpoint.ipynb index f4c7391..5b8075e 100644 --- a/.ipynb_checkpoints/lab-python-flow-control-checkpoint.ipynb +++ b/.ipynb_checkpoints/lab-python-flow-control-checkpoint.ipynb @@ -37,6 +37,118 @@ "\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": 1, + "id": "0a84256c-aae8-4c1a-99df-ff67cbe76dbc", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity of t-shirt: 100\n", + "Enter the quantity of mug: 200\n", + "Enter the quantity of hat: 300\n", + "Enter the quantity of book: 400\n", + "Enter the quantity of keychain: 500\n", + "Enter the name of a product you want to order: mug\n", + "Do you want to add another product? yes/no: no\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 1\n", + "Percentage of Products Ordered: 20.0 %\n", + "Updated Inventory:\n", + "t-shirt: 100\n", + "mug: 199\n", + "hat: 300\n", + "book: 400\n", + "keychain: 500\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " product = input(\"Enter the name of a product you want to order: \").lower()\n", + "\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"This product is not available.\")\n", + "\n", + " another = input(\"Do you want to add another product? yes/no: \").lower()\n", + "\n", + " if another != \"yes\":\n", + " break\n", + "\n", + "\n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "\n", + "percentage_ordered = (\n", + " total_products_ordered / len(products)\n", + ") * 100\n", + "\n", + "order_status = (\n", + " total_products_ordered,\n", + " percentage_ordered\n", + ")\n", + "\n", + "\n", + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1], \"%\")\n", + "\n", + "\n", + "print(\"Updated Inventory:\")\n", + "\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e6bd982-b5ff-4bc8-9ade-bd41274179da", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cd1111d3-a9b9-401a-b987-41abd4aa9247", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41a2dbc0-82b3-426b-bbf2-6ec0e1c6b8f8", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -55,7 +167,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.14" } }, "nbformat": 4, diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index c4862c0..5b8075e 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -13,9 +13,7 @@ { "cell_type": "markdown", "id": "3851fcd1-cf98-4653-9c89-e003b7ec9400", - "metadata": { - "jp-MarkdownHeadingCollapsed": true - }, + "metadata": {}, "source": [ "## Exercise: Managing Customer Orders Optimized\n", "\n", @@ -39,6 +37,118 @@ "\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": 1, + "id": "0a84256c-aae8-4c1a-99df-ff67cbe76dbc", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity of t-shirt: 100\n", + "Enter the quantity of mug: 200\n", + "Enter the quantity of hat: 300\n", + "Enter the quantity of book: 400\n", + "Enter the quantity of keychain: 500\n", + "Enter the name of a product you want to order: mug\n", + "Do you want to add another product? yes/no: no\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 1\n", + "Percentage of Products Ordered: 20.0 %\n", + "Updated Inventory:\n", + "t-shirt: 100\n", + "mug: 199\n", + "hat: 300\n", + "book: 400\n", + "keychain: 500\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " product = input(\"Enter the name of a product you want to order: \").lower()\n", + "\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"This product is not available.\")\n", + "\n", + " another = input(\"Do you want to add another product? yes/no: \").lower()\n", + "\n", + " if another != \"yes\":\n", + " break\n", + "\n", + "\n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "\n", + "percentage_ordered = (\n", + " total_products_ordered / len(products)\n", + ") * 100\n", + "\n", + "order_status = (\n", + " total_products_ordered,\n", + " percentage_ordered\n", + ")\n", + "\n", + "\n", + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1], \"%\")\n", + "\n", + "\n", + "print(\"Updated Inventory:\")\n", + "\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e6bd982-b5ff-4bc8-9ade-bd41274179da", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cd1111d3-a9b9-401a-b987-41abd4aa9247", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41a2dbc0-82b3-426b-bbf2-6ec0e1c6b8f8", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {