From 99e930608ea530f6b14b5072780a34315ac0ddd8 Mon Sep 17 00:00:00 2001 From: VIktoria Gluhovskayae Date: Sat, 21 Jun 2025 10:53:59 +0200 Subject: [PATCH] soled lab --- lab-python-data-structures.ipynb | 80 +++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..20524f5d 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,87 @@ "\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": "stdout", + "output_type": "stream", + "text": [ + "Enter the quantity for each product:\n", + "Enter 3 products the customer wants to order:\n", + "Customer Ordered Products:\n", + "mug\n", + "book\n", + "hat\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n", + "Updated Inventory:\n", + "t-shirt: 25\n", + "mug: 34\n", + "hat: 44\n", + "book: 54\n", + "keychain: 65\n" + ] + } + ], + "source": [ + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "print(\"Enter the quantity for each product:\")\n", + "for item in products:\n", + " quantity = int(input(f\"{item}: \"))\n", + " inventory[item] = quantity \n", + "\n", + "customer_orders = set()\n", + "\n", + "print(\"Enter 3 products the customer wants to order:\")\n", + "for i in range(3):\n", + " product = input(f\"Product {i+1}: \").strip().lower()\n", + " if product in products:\n", + " customer_orders.add(product) \n", + " else:\n", + " print(\"Invalid product. Skipped.\") \n", + "\n", + "print(\"Customer Ordered Products:\")\n", + "for item in customer_orders:\n", + " print(item)\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "order_status = (total_products_ordered, round(percentage_ordered, 2)) \n", + "\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n", + "\n", + "for item in customer_orders:\n", + " if inventory[item] > 0:\n", + " inventory[item] -= 1 \n", + "\n", + "print(\"Updated Inventory:\")\n", + "for item in products:\n", + " print(f\"{item}: {inventory[item]}\")\n", + "\n", + "\n", + " \n", + "\n", + "\n", + "\n", + "\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +144,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,