From 2bfe2a982637a19806d826ff6adbc2c17e13c8c2 Mon Sep 17 00:00:00 2001 From: galihwasena Date: Tue, 7 Oct 2025 17:27:49 +0200 Subject: [PATCH 1/2] week1 lab1 done --- .DS_Store | Bin 0 -> 6148 bytes lab-python-data-structures 2.ipynb | 213 +++++++++++++++++++++++++++++ lab-python-data-structures.ipynb | 76 ---------- 3 files changed, 213 insertions(+), 76 deletions(-) create mode 100644 .DS_Store create mode 100644 lab-python-data-structures 2.ipynb delete mode 100644 lab-python-data-structures.ipynb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0782fa9a2a597195fdfd3b27ab536c6b9ea80de6 GIT binary patch literal 6148 zcmeHKF;2r!47DLcq%Iv9{|S(KgHIF|)-H^wRBDl0r338Q76+q86 zt7m~+sQ?wA0^bVQ_aVUzbHP5)KOI&Q%=@0p{SpZc=B@59LSXlP=T=mm$98&|G$Nwng7Qm?x+A2_)`jK z)h^oxuT*;L\n", + " Percentage of Products Ordered: % \n", + " ```\n", + "\n", + "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "\n", + "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "\n", + "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "unexpected character after line continuation character (3726679577.py, line 13)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[5], line 13\u001b[0;36m\u001b[0m\n\u001b[0;31m print(n\\Available products, products)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unexpected character after line continuation character\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "inventory[\"t-shirt\"] = int(input(\"Enter the quantity of t-shirt: \"))\n", + "inventory[\"mug\"] = int(input(\"Enter the quantity of mug: \"))\n", + "inventory[\"hat\"] = int(input(\"Enter the quantity of hat: \"))\n", + "inventory[\"book\"] = int(input(\"Enter the quantity of book: \"))\n", + "inventory[\"keychain\"] = int(input(\"Enter the quantity of keychain: \"))\n", + "\n", + "print(\"\\nInventory created:\", inventory)\n", + "\n", + "customer_orders = set()\n", + "print(n\\Available products, products)\n", + "print(\"Please enter the products you'd like:\")\n", + "\n", + "item = input(f\"Product {}: \").lower()\n", + "item = input(f\"Product {}: \").lower()\n", + "item = input(f\"Product {}: \").lower()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity of t-shirt: 5\n", + "Enter the quantity of mug: 5\n", + "Enter the quantity of hat: 5\n", + "Enter the quantity of book: 5\n", + "Enter the quantity of keychain: 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\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", + "Please enter three products you'd like to order:\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Product 1: t-shirt\n", + "Product 2: mug\n", + "Product 3: hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Customer order set: {'mug', 'hat', 't-shirt'}\n", + "\n", + "Order Statistics:\n", + "Total 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: 4\n", + "keychain: 4\n" + ] + } + ], + "source": [ + "# Step 1: Define product list\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Step 2: Create inventory and ask for quantities\n", + "inventory = {}\n", + "inventory[\"t-shirt\"] = int(input(\"Enter the quantity of t-shirt: \"))\n", + "inventory[\"mug\"] = int(input(\"Enter the quantity of mug: \"))\n", + "inventory[\"hat\"] = int(input(\"Enter the quantity of hat: \"))\n", + "inventory[\"book\"] = int(input(\"Enter the quantity of book: \"))\n", + "inventory[\"keychain\"] = int(input(\"Enter the quantity of keychain: \"))\n", + "\n", + "print(\"\\nInventory created:\", inventory)\n", + "\n", + "# Step 3: Ask user for 3 products and store in a set\n", + "customer_orders = set()\n", + "print(\"\\nAvailable products:\", products)\n", + "print(\"Please enter three products you'd like to order:\")\n", + "\n", + "for i in range(3):\n", + " item = input(f\"Product {i+1}: \").lower()\n", + " if item in products:\n", + " customer_orders.add(item)\n", + " else:\n", + " print(\"Invalid product, please choose from:\", products)\n", + "\n", + "print(\"\\nCustomer order set:\", customer_orders)\n", + "\n", + "# Step 4: Calculate order statistics\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "# Step 5: Update inventory (subtract 1 from each)\n", + "for item in inventory:\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 [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb deleted file mode 100644 index 5b3ce9e0..00000000 --- a/lab-python-data-structures.ipynb +++ /dev/null @@ -1,76 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "# Lab | Data Structures " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Exercise: Managing Customer Orders\n", - "\n", - "As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.\n", - "\n", - "Follow the steps below to complete the exercise:\n", - "\n", - "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", - "\n", - "2. Create an empty dictionary called `inventory`.\n", - "\n", - "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", - "\n", - "4. Create an empty set called `customer_orders`.\n", - "\n", - "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n", - "\n", - "6. Print the products in the `customer_orders` set.\n", - "\n", - "7. Calculate the following order statistics:\n", - " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", - " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", - " \n", - " Store these statistics in a tuple called `order_status`.\n", - "\n", - "8. Print the order statistics using the following format:\n", - " ```\n", - " Order Statistics:\n", - " Total Products Ordered: \n", - " Percentage of Products Ordered: % \n", - " ```\n", - "\n", - "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", - "\n", - "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", - "\n", - "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " - ] - } - ], - "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": 4 -} From 7c6ad5fb3ec07777ab8ae5eaacf5305e3c6aa343 Mon Sep 17 00:00:00 2001 From: galihwasena Date: Thu, 9 Oct 2025 01:48:12 +0200 Subject: [PATCH 2/2] lab day 1 done --- .DS_Store | Bin 6148 -> 6148 bytes lab-python-data-structures 2.ipynb | 39 ++--------------------------- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/.DS_Store b/.DS_Store index 0782fa9a2a597195fdfd3b27ab536c6b9ea80de6..cde694a5229828546f190212f1100f93dabf256e 100644 GIT binary patch delta 113 zcmZoMXfc?uEOsU{0|NsKgC0XVLncE>ZoZ34QcivnP>chJ>$Z3ucSMy>!7E>oVHlj8 apIZRb!@$6luvw7t8{5PJzRm0$fB6CVDjP!p delta 113 zcmZoMXfc?uEVkQ;fq{XAL60GwA(NpbH{Zo2DJMS(D8{iqB7=L2*KtQw`4qhJ1sR6H c$@#ejKs^i$j2|`&GJa#5SirZLo#QV*0F!qe`v3p{ diff --git a/lab-python-data-structures 2.ipynb b/lab-python-data-structures 2.ipynb index e8cdfa52..610b689a 100644 --- a/lab-python-data-structures 2.ipynb +++ b/lab-python-data-structures 2.ipynb @@ -51,48 +51,13 @@ "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "unexpected character after line continuation character (3726679577.py, line 13)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m Cell \u001b[0;32mIn[5], line 13\u001b[0;36m\u001b[0m\n\u001b[0;31m print(n\\Available products, products)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unexpected character after line continuation character\n" - ] - } - ], - "source": [ - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", - "\n", - "inventory = {}\n", - "inventory[\"t-shirt\"] = int(input(\"Enter the quantity of t-shirt: \"))\n", - "inventory[\"mug\"] = int(input(\"Enter the quantity of mug: \"))\n", - "inventory[\"hat\"] = int(input(\"Enter the quantity of hat: \"))\n", - "inventory[\"book\"] = int(input(\"Enter the quantity of book: \"))\n", - "inventory[\"keychain\"] = int(input(\"Enter the quantity of keychain: \"))\n", - "\n", - "print(\"\\nInventory created:\", inventory)\n", - "\n", - "customer_orders = set()\n", - "print(n\\Available products, products)\n", - "print(\"Please enter the products you'd like:\")\n", - "\n", - "item = input(f\"Product {}: \").lower()\n", - "item = input(f\"Product {}: \").lower()\n", - "item = input(f\"Product {}: \").lower()\n" - ] - }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { - "name": "stdin", + "name": "stdout", "output_type": "stream", "text": [ "Enter the quantity of t-shirt: 5\n", @@ -114,7 +79,7 @@ ] }, { - "name": "stdin", + "name": "stdout", "output_type": "stream", "text": [ "Product 1: t-shirt\n",