From 806cffd525ed78861ec1f980e188b6bc0dcd2347 Mon Sep 17 00:00:00 2001 From: Elena Garrigues Pascual Date: Mon, 15 Jun 2026 17:50:40 +0200 Subject: [PATCH] Solved lab day1 --- lab-python-data-structures.ipynb | 357 ++++++++++++++++++++++++++++++- 1 file changed, 355 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..e1e337db 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,364 @@ "\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": 143, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 144, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']" + ] + }, + "execution_count": 144, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "products" + ] + }, + { + "cell_type": "code", + "execution_count": 145, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 146, + "metadata": {}, + "outputs": [], + "source": [ + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {products}: \"))\n", + " inventory[product] = quantity\n" + ] + }, + { + "cell_type": "code", + "execution_count": 147, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "set()" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [], + "source": [ + "product1 = input(\"Enter the first product: \")\n", + "product2 = input(\"Enter the second product: \")\n", + "product3 = input(\"Enter the third product: \")\n", + "\n", + "customer_orders.add(product1)\n", + "customer_orders.add(product2)\n", + "customer_orders.add(product3)" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'hat', 'mug'}" + ] + }, + "execution_count": 96, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": {}, + "outputs": [], + "source": [ + "len(customer_orders)\n", + "total_customer_orders = len(customer_orders)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 103, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "total_customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [], + "source": [ + "percentage_ordered = ((len(customer_orders)) / (len(products))) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "60.0" + ] + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "percentage_ordered" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 60.0)" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "order_status = (total_customer_orders, percentage_ordered)\n", + "order_status" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0 %\n" + ] + } + ], + "source": [ + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", total_customer_orders)\n", + "print(\"Percentage of Products Ordered:\", percentage_ordered, \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 148, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 149, + "metadata": {}, + "outputs": [], + "source": [ + "inventory[\"t-shirt\"] = inventory[\"t-shirt\"] - 1" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 0, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 150, + "metadata": {}, + "outputs": [], + "source": [ + "inventory[\"mug\"] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 0, 'mug': 1, 'hat': 3, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 152, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 0, 'mug': 1, 'hat': 2, 'book': 3, 'keychain': 4}\n" + ] + } + ], + "source": [ + "inventory[\"hat\"] -= 1\n", + "inventory[\"book\"] -= 1\n", + "inventory[\"keychain\"] -= 1\n", + "\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 0\n", + "mug: 1\n", + "hat: 2\n", + "book: 3\n", + "keychain: 4\n" + ] + } + ], + "source": [ + "print('t-shirt:', inventory['t-shirt'])\n", + "print(\"mug:\", inventory[\"mug\"])\n", + "print(\"hat:\", inventory[\"hat\"])\n", + "print(\"book:\", inventory[\"book\"])\n", + "print(\"keychain:\", inventory[\"keychain\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +421,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,