From 2bb181d3a2509599a583dd0119ac9ad28e7a66d3 Mon Sep 17 00:00:00 2001 From: VIktoria Gluhovskayae Date: Sat, 21 Jun 2025 11:36:29 +0200 Subject: [PATCH] Sloved lab --- lab-python-functions.ipynb | 94 +++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..7a1f02f 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,101 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "ac28b383", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the quantity for each product:\n", + "Enter the products the customer wants to order:\n", + "Invalid product. Please choose from the available products.\n", + "Order Statistics:\n", + "Total Products Ordered: 0\n", + "Percentage of Products Ordered: 0.0%\n", + "Updated Inventory:\n", + "t-shirt: 25\n", + "mug: 35\n", + "hat: 45\n", + "book: 55\n", + "keychain: 65\n" + ] + } + ], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + " print(\"Enter the quantity for each product:\")\n", + " for item in products:\n", + " quantity = int(input(f\"{item}: \"))\n", + " inventory[item] = quantity\n", + " return inventory\n", + "\n", + "def get_customer_orders(products):\n", + " customer_orders = set()\n", + " print(\"Enter the products the customer wants to order:\")\n", + " while True:\n", + " product = input(\"Enter product name: \").strip().lower()\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Invalid product. Please choose from the available products.\")\n", + "\n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break\n", + " return customer_orders\n", + "\n", + "def update_inventory(customer_orders, inventory):\n", + " for item in customer_orders:\n", + " if inventory.get(item, 0) > 0:\n", + " inventory[item] -= 1\n", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_ordered = len(customer_orders)\n", + " percentage = (total_ordered / len(products)) * 100\n", + " return (total_ordered, round(percentage, 2))\n", + "\n", + "def print_order_statistics(order_statistics):\n", + " print(\"Order Statistics:\")\n", + " print(f\"Total Products Ordered: {order_statistics[0]}\")\n", + " print(f\"Percentage of Products Ordered: {order_statistics[1]}%\")\n", + "\n", + "def print_updated_inventory(inventory):\n", + " print(\"Updated Inventory:\")\n", + " for item, quantity in inventory.items():\n", + " print(f\"{item}: {quantity}\")\n", + "\n", + "def main():\n", + " products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + " inventory = initialize_inventory(products)\n", + " customer_orders = get_customer_orders(products)\n", + " update_inventory(customer_orders, inventory)\n", + " order_stats = calculate_order_statistics(customer_orders, products)\n", + " print_order_statistics(order_stats)\n", + " print_updated_inventory(inventory)\n", + "\n", + "main()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c205dafa", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +151,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,