From a487df0f254b1d77d005f47242a35c94e18fcce3 Mon Sep 17 00:00:00 2001 From: Safina E Jahan Date: Fri, 28 Nov 2025 22:56:08 +0100 Subject: [PATCH] solved_lab-python-flow-control --- .../lab-python-flow-control-checkpoint.ipynb | 63 ++++++++ anaconda_projects/db/project_filebrowser.db | Bin 0 -> 32768 bytes lab-python-flow-control.ipynb | 141 +++++++++++++++++- 3 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 .ipynb_checkpoints/lab-python-flow-control-checkpoint.ipynb create mode 100644 anaconda_projects/db/project_filebrowser.db 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 +} diff --git a/anaconda_projects/db/project_filebrowser.db b/anaconda_projects/db/project_filebrowser.db new file mode 100644 index 0000000000000000000000000000000000000000..3fa3a4a02c0753b66dd6cf65930b505be899ade0 GIT binary patch literal 32768 zcmeI)PjAv-9Ki9GZT#Ch^u&qe$&zJ|Et)Z>@nB-b8W)iXE5^kvO$QIA2!%mGubW3t zdl9|}Ux^oAgh!9Igf2kl;=zNd--ch>=XvOp=lS%PCQn*8s+Jv3idJvXwLP(?+)`9k zc`SsYD64)X{fPS!^CRuYvLE55h6gw7SCu>C&zkm4Sy{VOGg{{B+NJho{kzuI+Bcj< z69NbzfB*srAbc%c7q{byY%ZsM8hQ3z(-g1uTIso76O}_#RO;pOj!37Pwr2~|cw+{I-Un9>u1c=mmD55~w(L>Iv!pwA z20gbcUGJ*5r^YkAUN*(n)=bBq{cbopS6nr}J(>MNI`yh{@KUcGixM|9wNuCD2TNeoj1! z#k1Az-{r(&XS)j(Oa9FySlcU_A8O`@;(yo>KmY**5I_I{1Q0*~0R#|0AR+?mYHYLh zVE^I%>Am~KU0Dns>a+fj$i-zE2q1s}0tg_000IagfB*srOa(Gao2l9LfAIX@f9anM z0R#|0009ILKmY**5I_I{1R^ZJ`ai-Km#HCu00IagfB*srAb|BuSmWF810fB*srAb 0:\n", + " # Update the inventory by subtracting 1\n", + " inventory[product] -= 1\n", + " print(f\"Inventory for '{product}' updated. New quantity: {inventory[product]}\")\n", + " else:\n", + " print(f\"Warning: '{product}' is out of stock and could not be fulfilled.\")\n", + " \n", + "# Final output\n", + "print(\"\\n--- Final Inventory Status ---\")\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3cb0a9f8-241c-4286-b3fd-8ecc95b82119", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -55,7 +190,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,