From 742d7944ab00a03bea4e504fca5fa891ebd846fc Mon Sep 17 00:00:00 2001 From: Kseniia Iukhlina Date: Tue, 21 Jul 2026 22:15:30 +0200 Subject: [PATCH] The lab for python data structure was completed --- lab-python-data-structures.ipynb | 124 ++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..df1270b1 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,128 @@ "\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": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Please, enter the avaliable quantity of each product\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "t-shirt: 34\n", + "mug: 6\n", + "hat: 2\n", + "book: 4\n", + "keychain: 7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The following products are availiable in the stock: {'t-shirt': 34, 'mug': 6, 'hat': 2, 'book': 4, 'keychain': 7}\n", + "To complete your order, enter three product name separated by space\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + " hat t-shirt book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your order contains this products: {'t-shirt', 'hat', 'book'}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "print(\"Please, enter the avaliable quantity of each product\")\n", + "for i in products:\n", + " inp = int(input(\"{}: \".format(i)))\n", + " inventory[i] = inp\n", + "print(\"The following products are availiable in the stock:\", inventory)\n", + "customer_orders = {} \n", + "print(\"To complete your order, enter three product name separated by space\")\n", + "\n", + "item_1, item_2, item_3 = input(\" \").split()\n", + "customer_orders = {item_1, item_2, item_3}\n", + "print(\"Your order contains this products:\", customer_orders)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Order Statistics**" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60%\n" + ] + } + ], + "source": [ + "print(\"Total Products Ordered: {}\".format(len(customer_orders)))\n", + "print(\"Percentage of Products Ordered: {}%\".format(int(len(customer_orders)*100/len(products))))" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The following products are availiable in the stock: {'t-shirt': 33, 'mug': 6, 'hat': 1, 'book': 3, 'keychain': 7}\n" + ] + } + ], + "source": [ + "for i in customer_orders:\n", + " inventory[i] = int(inventory[i]) - 1\n", + " \n", + "print(\"The following products are availiable in the stock:\", inventory) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,7 +190,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,