From 861bc3f7a6414dc1b24f41b00b1f290c3b89990e Mon Sep 17 00:00:00 2001 From: Marta Date: Thu, 20 Nov 2025 10:59:12 +0100 Subject: [PATCH] Uploaded my lab with my answers --- lab-python-data-structures.ipynb | 100 ++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..5c817123 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,104 @@ "\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": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity available of t-shirt please: 50\n", + "Enter the quantity available of mug please: 50\n", + "Enter the quantity available of hat please: 60\n", + "Enter the quantity available of book please: 40\n", + "Enter the quantity available of keychain please: 30\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity available of {product} please: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter a product out of the previous list: book\n", + "Please enter a product out of the previous list: hat\n", + "Please enter a product out of the previous list: mug\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'book', 'mug'}\n", + "3\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n", + "t-shirt: 49\n", + "mug: 49\n", + "hat: 59\n", + "book: 39\n", + "keychain: 29\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "print(products)\n", + "\n", + "for i in range(3):\n", + " products_ordered = input('Please enter a product out of the previous list: ')\n", + " customer_orders.add(products_ordered) \n", + " \n", + "print(customer_orders)\n", + "total_products_ordered = len(customer_orders) \n", + "print(total_products_ordered) \n", + "\n", + "float_products_ordered = float(total_products_ordered)\n", + "porcentage_ordered = float_products_ordered/5*100\n", + "order_status = (total_products_ordered, porcentage_ordered)\n", + "\n", + "print('Order Statistics:')\n", + "print(f'Total Products Ordered: {total_products_ordered}') \n", + "print(f'Percentage of Products Ordered: {porcentage_ordered}%')\n", + "\n", + "for product_name in inventory:\n", + " inventory[product_name] -= 1\n", + "\n", + "for product_name, quantity in inventory.items():\n", + " print(f\"{product_name}: {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,7 +166,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,