From 8fae468c94a1d649636d544ff97d38112b363bdb Mon Sep 17 00:00:00 2001 From: galihwasena007-cell Date: Thu, 9 Oct 2025 02:18:51 +0200 Subject: [PATCH 1/2] lab2 done --- lab-python-flow-control.ipynb | 98 ++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..248a5dd 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,105 @@ "\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": "dc8121b5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter initial inventory quantities:\n", + "\n", + "Inventory created: {'t-shirt': 5, 'mug': 5, 'hat': 5, 'book': 5, 'keychain': 5}\n", + "\n", + "Available products: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "Added 't-shirt'. Current order (unique): {'t-shirt'}\n", + "Added 'mug'. Current order (unique): {'t-shirt', 'mug'}\n", + "Added 'hat'. Current order (unique): {'t-shirt', 'hat', 'mug'}\n", + "\n", + "Customer order set (unique): {'t-shirt', 'hat', 'mug'}\n", + "\n", + "Order Statistics:\n", + "Total Unique Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n", + "\n", + "Updated Inventory:\n", + "t-shirt: 4\n", + "mug: 4\n", + "hat: 4\n", + "book: 5\n", + "keychain: 5\n" + ] + } + ], + "source": [ + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "print(\"Enter initial inventory quantities:\")\n", + "for p in products:\n", + " while True:\n", + " try:\n", + " qty = int(input(f\"Enter the quantity of {p}: \"))\n", + " if qty < 0:\n", + " print(\"Please enter a non-negative number.\")\n", + " continue\n", + " inventory[p] = qty\n", + " break\n", + " except ValueError:\n", + " print(\"Please enter a valid integer.\")\n", + "\n", + "print(\"\\nInventory created:\", inventory)\n", + "\n", + "customer_orders = set()\n", + "print(\"\\nAvailable products:\", products)\n", + "\n", + "while True:\n", + " item = input(\"\\nEnter a product to add to the order: \").strip().lower()\n", + " if item in products:\n", + " customer_orders.add(item)\n", + " print(f\"Added '{item}'. Current order (unique): {customer_orders}\")\n", + " else:\n", + " print(\"Invalid product, please choose from:\", products)\n", + " # don't ask to continue on invalid; loop back to ask for a valid product\n", + " continue\n", + "\n", + " \n", + " another = input(\"Add another product? (yes/no): \").strip().lower()\n", + " if another in (\"no\", \"n\"):\n", + " break\n", + " elif another in (\"yes\", \"y\"):\n", + " continue\n", + " else:\n", + " print(\"Didn't catch that—stopping here.\")\n", + " break\n", + "\n", + "print(\"\\nCustomer order set (unique):\", customer_orders)\n", + "\n", + "total_unique_ordered = len(customer_orders)\n", + "percentage_ordered = (total_unique_ordered / len(products)) * 100 if products else 0.0\n", + "\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Unique Products Ordered: {total_unique_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_ordered:.2f}%\")\n", + "\n", + "for item in customer_orders:\n", + " inventory[item] = max(0, inventory[item] - 1)\n", + "\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product, qty in inventory.items():\n", + " print(f\"{product}: {qty}\")\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +149,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.9.6" } }, "nbformat": 4, From 7ddf00c3b707cf5e96eb59c9951ca6493e4aa4ee Mon Sep 17 00:00:00 2001 From: galihwasena007-cell Date: Thu, 9 Oct 2025 02:35:45 +0200 Subject: [PATCH 2/2] lab2 work done --- .DS_Store | Bin 0 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e1a624b01f44561ee0130d78b6f5bd60113f0571 GIT binary patch literal 6148 zcmeHKF;2r!47E#!NGu&0{|S&fuz#v_V(bM_DJn><(xL3xn0o-ugSZ7p;0Qe1ACxF6 zBLh53{x9G5%TL}A$0DNhr}a!^Dk3%9P@ZiWo8`?%HYt$`sCJL-X12U*cl%N0>40%7 zxs;7O%3;Vq-uH96wrN(|c7<5|cJ)4axp}=F=GQ;w_Yb{i(+^N-RDcRl0V+TR{-pxw z*=F^5AXh3t1*pKc0``4KaKl`%3-nJ179RnC_8aepYo8^6$pXM!unR;4ra=V;Rm+H> zK}S55x?Hde47#YFjQf<6wM;1Lrz4)cTr>xAr2$M4f3;#0IdN~$v#XxVx*jOvR=+z~=Mm`tp0-cVy(}DaEFkNU= I;5QWb1d}!?fdBvi literal 0 HcmV?d00001