From 42c674dfeb6fb62695c49ce09b4e7a4f7fb391a4 Mon Sep 17 00:00:00 2001 From: Edosa Erhunmwunse Date: Fri, 10 Oct 2025 08:53:57 +0200 Subject: [PATCH] flow control --- lab-python-flow-control.ipynb | 123 +++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..5ad78ba 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,127 @@ "\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": 27, + "id": "2411affc-d8c5-4233-9ce9-e2d1dd08e2a3", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter name of product: mug\n", + "Enter yes or no to add another product: yes\n", + "Enter name of product: book\n", + "Enter yes or no to add another product: no\n" + ] + }, + { + "data": { + "text/plain": [ + "{'book', 'mug'}" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "x=len(products)\n", + "customer_order=set()\n", + "count=0\n", + "\n", + "for count in range(x):\n", + " name=input(\"Enter name of product: \")\n", + " if name in products:\n", + " customer_order.add(name)\n", + " ask=input(\"Enter yes or no to add another product: \")\n", + " if ask==\"yes\":\n", + " count+=1\n", + " elif ask==\"no\":\n", + " break\n", + " else:\n", + " print(\"please add available\")\n", + " \n", + "customer_order\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "d3e3747f-cde3-457f-bdce-5cc67df1ccf2", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter quantity: 2\n", + "Enter quantity: 3\n", + "Enter quantity: 4\n", + "Enter quantity: 5\n", + "Enter quantity: 6\n" + ] + }, + { + "data": { + "text/plain": [ + "{'t-shirt': 2, 'mug': 3, 'hat': 4, 'book': 5, 'keychain': 6}" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory=dict()\n", + "for i in products:\n", + " quantity=int(input(\"Enter quantity: \"))\n", + " inventory[i]=quantity\n", + " \n", + "inventory \n" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "942af08b-0509-4542-bb91-f1fca1712d06", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 2, 'mug': 2, 'hat': 4, 'book': 4, 'keychain': 6}" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "for i in customer_order:\n", + " if i in inventory:\n", + " inventory[i]-=1\n", + "\n", + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7d94412c-23c0-4bac-b222-c7f21408f294", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -55,7 +176,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,