From 3120ee99d2d926eba951d9c89e766c0af11c52d1 Mon Sep 17 00:00:00 2001 From: lenovo Date: Sun, 8 Jun 2025 18:46:35 +0200 Subject: [PATCH] ds lab completed --- lab-python-data-structures.ipynb | 98 +++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..6697aa32 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,105 @@ "\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": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "for quan_prod in products:\n", + " quantity = int(input(f\"Enter the quantity of {products} available in the inventory:\"))\n", + " inventory[quan_prod] = quantity\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'3', '2', '1'}\n" + ] + } + ], + "source": [ + "customer_order = set()\n", + "for pro in range(3):\n", + " product_name = input(\"Enter the name of three products that a customer wants to order: \")\n", + " customer_order.add(product_name)\n", + "print(customer_order)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "(3, 60.0)\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered:60.0%\n" + ] + } + ], + "source": [ + "total_products_ordered = len(customer_order)\n", + "print(total_products_ordered)\n", + "percentage_products_ordered = (total_products_ordered / len(products))*100\n", + "order_status = (total_products_ordered,percentage_products_ordered)\n", + "print(order_status)\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(f\"Percentage of Products Ordered:{order_status[1]}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt 3\n", + "mug 13\n", + "hat 23\n", + "book 33\n", + "keychain 43\n", + "{'t-shirt': 2, 'mug': 12, 'hat': 22, 'book': 32, 'keychain': 42}\n" + ] + } + ], + "source": [ + "for key, value in inventory.items():\n", + " inventory[key] = (value - 1)\n", + " print(key,value)\n", + "print(inventory)\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +162,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.9" } }, "nbformat": 4,