From e0b724804a5c106daa4be1150606b1b458af57ae Mon Sep 17 00:00:00 2001 From: Jessica Budwilowitz Date: Wed, 18 Jun 2025 10:00:03 +0200 Subject: [PATCH 1/2] Solved Lab --- lab-python-data-structures.ipynb | 76 ++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..a23c8e15 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,13 +50,83 @@ "\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": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter stock for article t-shirt 1\n", + "Please enter stock for article mug 2\n", + "Please enter stock for article hat 3\n", + "Please enter stock for article book 4\n", + "Please enter stock for article keychain 5\n", + "Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 1\n", + "Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 2\n", + "Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 'hat', 'book'}\n", + "3\n", + "20.0 %\n", + "The stock for t-shirt is 1\n", + "The stock for mug is 1\n", + "The stock for hat is 2\n", + "The stock for book is 3\n", + "The stock for keychain is 5\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " stock = int(input(f\"Please enter stock for article {product}\"))\n", + " inventory[product] = stock\n", + "\n", + "customer_orders = set()\n", + "\n", + "for purchase in range(3):\n", + " customer_orders.add(products[int(input(\"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain\"))])\n", + "\n", + "print(customer_orders)\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (len(customer_orders)/sum(inventory.values()))*100\n", + "\n", + "print(total_products_ordered)\n", + "print(percentage_ordered, \"%\")\n", + "\n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "for product in products:\n", + " print(\"The stock for\", product, \"is\", inventory[product])\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "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": { @@ -68,7 +138,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4, From 84537a82641c2b080e42bdf7e60784148676749a Mon Sep 17 00:00:00 2001 From: Jessica Budwilowitz Date: Wed, 18 Jun 2025 16:56:31 +0200 Subject: [PATCH 2/2] Solved Lab --- lab-python-data-structures.ipynb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index a23c8e15..d9e47949 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -75,8 +75,9 @@ "output_type": "stream", "text": [ "{'mug', 'hat', 'book'}\n", - "3\n", - "20.0 %\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0 %\n", "The stock for t-shirt is 1\n", "The stock for mug is 1\n", "The stock for hat is 2\n", @@ -102,10 +103,11 @@ "print(customer_orders)\n", "\n", "total_products_ordered = len(customer_orders)\n", - "percentage_ordered = (len(customer_orders)/sum(inventory.values()))*100\n", + "percentage_ordered = (len(customer_orders)/len(inventory.values()))*100\n", "\n", - "print(total_products_ordered)\n", - "print(percentage_ordered, \"%\")\n", + "print(f\"\"\"Order Statistics:\n", + "Total Products Ordered: {total_products_ordered}\n", + "Percentage of Products Ordered: {percentage_ordered} %\"\"\")\n", "\n", "for product in customer_orders:\n", " inventory[product] -= 1\n",